Skip to content

Commit cb3c063

Browse files
committed
refactor: nicer output formatting
1 parent 6016bb9 commit cb3c063

File tree

7 files changed

+281
-247
lines changed

7 files changed

+281
-247
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"node": ">=18.0.0"
2626
},
2727
"dependencies": {
28-
"@salesforce/core": "^8.2.1",
28+
"@salesforce/core": "^8.2.3",
2929
"@salesforce/kit": "^3.1.6",
3030
"@salesforce/ts-types": "^2.0.10",
3131
"fast-levenshtein": "^3.0.0",
@@ -41,7 +41,7 @@
4141
"devDependencies": {
4242
"@jsforce/jsforce-node": "^3.2.4",
4343
"@salesforce/cli-plugins-testkit": "^5.3.18",
44-
"@salesforce/dev-scripts": "^10.2.2",
44+
"@salesforce/dev-scripts": "^10.2.4",
4545
"@types/deep-equal-in-any-order": "^1.0.1",
4646
"@types/fast-levenshtein": "^0.0.4",
4747
"@types/graceful-fs": "^4.1.9",

src/collections/componentSetBuilder.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,15 @@ const addToComponentSet =
215215
};
216216

217217
const componentSetBuilderErrorHandler = (e: unknown): never => {
218-
if (e instanceof Error && e.message.includes('Missing metadata type definition in registry for id')) {
219-
// to remain generic to catch missing metadata types regardless of parameters, split on '
220-
// example message : Missing metadata type definition in registry for id 'NonExistentType'
221-
const issueType = e.message.split("'")[1];
222-
throw new SfError(`The specified metadata type is unsupported: [${issueType}]`);
223-
} else {
224-
throw e;
225-
}
218+
// if (e instanceof Error && e.message.includes('Missing metadata type definition in registry for id')) {
219+
// console.log(e);
220+
// // to remain generic to catch missing metadata types regardless of parameters, split on '
221+
// // example message : Missing metadata type definition in registry for id 'NonExistentType'
222+
// const issueType = e.message.split("'")[1];
223+
// throw new SfError(`The specified metadata type is unsupported: [${issueType}]`);
224+
// } else {
225+
throw e;
226+
// }
226227
};
227228

228229
const validateAndResolvePath = (filepath: string): string => path.resolve(assertFileExists(filepath));

src/registry/levenshtein.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ export const getTypeSuggestions = (registry: MetadataRegistry, typeName: string)
1919
typeName
2020
);
2121

22-
const guesses = getLowestScores(scores);
23-
return guesses.length
24-
? [
25-
'Did you mean one of the following types?',
26-
...guesses.map((guess) => guess.registryKey),
27-
...messages.getMessages('type_name_suggestions'),
28-
]
29-
: messages.getMessages('type_name_suggestions');
22+
const guesses = getLowestScores(scores).map((guess) => guess.registryKey);
23+
return [
24+
...(guesses.length
25+
? [
26+
`Did you mean one of the following types? [${guesses.join(',')}]`,
27+
'', // Add a blank line for better readability
28+
]
29+
: []),
30+
messages.getMessage('type_name_suggestions'),
31+
];
3032
};
3133

3234
export const getSuffixGuesses = (suffixes: string[], input: string): string[] => {

src/registry/registryAccess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class RegistryAccess {
5151
}
5252
if (!this.registry.types[lower]) {
5353
throw SfError.create({
54-
message: messages.getMessage('error_missing_type_definition', [lower]),
54+
message: messages.getMessage('error_missing_type_definition', [name]),
5555
name: 'RegistryError',
5656
actions: getTypeSuggestions(this.registry, lower),
5757
});

test/collections/componentSetBuilder.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ describe('ComponentSetBuilder', () => {
249249
assert.fail('the above should throw an error');
250250
} catch (e) {
251251
expect(e).to.not.be.null;
252-
expect((e as Error).message).to.include('The specified metadata type is unsupported: [notatype]');
252+
expect((e as Error).message).to.include("Missing metadata type definition in registry for id 'NotAType'");
253253
}
254254
});
255255

test/registry/registryAccess.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ describe('RegistryAccess', () => {
4040
assert.throws(
4141
() => registryAccess.getTypeByName('TypeWithoutDef'),
4242
SfError,
43-
messages.getMessage('error_missing_type_definition', ['typewithoutdef'])
43+
messages.getMessage('error_missing_type_definition', ['TypeWithoutDef'])
4444
);
4545
});
4646

4747
describe('suggestions for type name', () => {
48-
it('should provide suggestions for unresolvable types that are close', () => {
48+
it('should suggest Workflow for Worflow (sic)', () => {
4949
try {
5050
registryAccess.getTypeByName('Worflow');
5151
} catch (e) {
5252
assert(e instanceof SfError);
5353
expect(e.actions).to.have.length.greaterThan(0);
54-
expect(e.actions).to.deep.include('Workflow');
54+
expect(e.actions?.join()).to.include('Workflow');
5555
}
5656
});
5757
it('should provide several suggestions for unresolvable types that are nowhere', () => {

0 commit comments

Comments
 (0)