Skip to content

Commit

Permalink
Improve pull error message
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-tpom6oh committed Nov 15, 2024
1 parent e334368 commit 6e15351
Showing 1 changed file with 53 additions and 45 deletions.
98 changes: 53 additions & 45 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,9 @@ function responseToError(response, error) {
};
}

const message = `HTTP Error: ${response.statusCode}, ${body.error.message ?? body.error
}`;
const message = `HTTP Error: ${response.statusCode}, ${
body.error.message ?? body.error
}`;

let exitCode;
if (response.statusCode >= 500) {
Expand Down Expand Up @@ -262,8 +263,8 @@ function _request(options) {
original: err,
exit: 2,
}),
)
};
);
}
});
});
}
Expand Down Expand Up @@ -946,7 +947,8 @@ function resolveAvoJsonConflicts(
.then(([isDone, json]) => {
if (!isDone && isIncomingBranchOpen && argv.force) {
report.warn(
`Incoming branch, ${incoming.branch.name
`Incoming branch, ${
incoming.branch.name
}, has not been merged to Avo main. To review and merge go to: ${link(
`https://www.avo.app/schemas/${nextAvoJson.schema.id}/branches/${incoming.branch.id}/diff`,
)}`,
Expand All @@ -963,7 +965,8 @@ function resolveAvoJsonConflicts(
branchName: head.branch.name,
});
throw new Error(
`Incoming branch, ${incoming.branch.name
`Incoming branch, ${
incoming.branch.name
}, has not been merged to Avo main.\n\nTo review and merge go to:\n${link(
`https://www.avo.app/schemas/${nextAvoJson.schema.id}/branches/${incoming.branch.id}/diff`,
)}\n\nOnce merged, run 'avo pull'. To skip this check use the --force flag.`,
Expand Down Expand Up @@ -1101,7 +1104,8 @@ function codegen(
}

report.success(
`Analytics ${targets.length > 1 ? 'wrappers' : 'wrapper'
`Analytics ${
targets.length > 1 ? 'wrappers' : 'wrapper'
} successfully updated`,
);
targets.forEach((target) => {
Expand Down Expand Up @@ -1222,31 +1226,31 @@ function selectSource(sourceToAdd: string, json: AvoJson) {
const moreAnswers = await inquirer.prompt(
answerSource.canHaveInterfaceFile === true
? [
{
type: 'fuzzypath',
name: 'folder',
excludePath: (maybeExcludePath) =>
maybeExcludePath.startsWith('node_modules') ||
maybeExcludePath.startsWith('.git'),
itemType: 'directory',
rootPath: '.',
message:
'Select a folder to save the analytics wrapper interface file in',
default: '.',
suggestOnly: false,
depthLimit: 10,
},
{
type: 'input',
name: 'interfaceFilename',
message: (_answers) =>
'Select a filename for the analytics wrapper interface file',
// @ts-ignore
default() {
return answerSource.filenameHint;
{
type: 'fuzzypath',
name: 'folder',
excludePath: (maybeExcludePath) =>
maybeExcludePath.startsWith('node_modules') ||
maybeExcludePath.startsWith('.git'),
itemType: 'directory',
rootPath: '.',
message:
'Select a folder to save the analytics wrapper interface file in',
default: '.',
suggestOnly: false,
depthLimit: 10,
},
{
type: 'input',
name: 'interfaceFilename',
message: (_answers) =>
'Select a filename for the analytics wrapper interface file',
// @ts-ignore
default() {
return answerSource.filenameHint;
},
},
},
]
]
: [],
);
const hasMultiPath = moreAnswers.interfaceFilename != null;
Expand Down Expand Up @@ -1345,7 +1349,8 @@ function pull(sourceFilter, json: AvoJson): Promise<void> {
codegen(json, result);
} else {
report.error(
`Branch ${result.branchName} was ${result.reason
`Branch ${result.branchName} was ${
result.reason
} ${dateFns.formatDistance(
new Date(),
new Date(result.closedAt),
Expand Down Expand Up @@ -1545,7 +1550,7 @@ function status(source: string, json, argv: any): void {
const globs: Minimatch[] = [
new Minimatch(
source.analysis?.glob ??
`**/*.+(${sourcePathExts.join('|')})`,
`**/*.+(${sourcePathExts.join('|')})`,
{},
),
new Minimatch(`!${source.path}`, {}),
Expand Down Expand Up @@ -1604,14 +1609,15 @@ function status(source: string, json, argv: any): void {
children:
Object.keys(results).length > 0
? Object.entries(results).map(([matchFile, result]) => ({
name: `used in ${matchFile}: ${result.length}${result.length === 1 ? ' time' : ' times'
name: `used in ${matchFile}: ${result.length}${
result.length === 1 ? ' time' : ' times'
}`,
}))
}))
: [
{
name: `${logSymbols.error} no usage found`,
},
],
{
name: `${logSymbols.error} no usage found`,
},
],
}),
),
})),
Expand Down Expand Up @@ -1640,13 +1646,15 @@ function status(source: string, json, argv: any): void {
}
} else {
report.info(
`${totalEvents - missingEvents
`${
totalEvents - missingEvents
} of ${totalEvents} events seen in code`,
);
}
if (missingEvents > 0) {
report.error(
`${missingEvents} missing ${missingEvents > 1 ? 'events' : 'event'
`${missingEvents} missing ${
missingEvents > 1 ? 'events' : 'event'
}`,
);
report.tree(
Expand All @@ -1657,10 +1665,10 @@ function status(source: string, json, argv: any): void {
.map(([eventName, results]) =>
Object.keys(results).length === 0
? [
{
name: `${red(eventName)}: no usage found`,
},
]
{
name: `${red(eventName)}: no usage found`,
},
]
: [],
)
.flat(),
Expand Down

0 comments on commit 6e15351

Please sign in to comment.