Skip to content

Commit

Permalink
refactor: placeholders for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jul 19, 2024
1 parent d94960b commit 53babf0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/convert/transformers/staticResourceMetadataTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class StaticResourceMetadataTransformer extends BaseMetadataTransformer {

// Zip the static resource from disk to a stream, compressing at level 9.
const zipIt = (): Readable => {
// static resource should always have content prop
getLogger().debug(`zipping static resource: ${content}`);
const zip = JSZip();

Expand Down Expand Up @@ -198,7 +197,7 @@ const getContentType = async (component: SourceComponent): Promise<string> => {

if (typeof output !== 'string') {
throw new SfError(
`Expected a string for contentType in ${component.name} (${component.xml ?? ''}) but got ${JSON.stringify(
`Expected a string for contentType in ${component.name} (${component.xml ?? '<no xml>'}) but got ${JSON.stringify(
output
)}`
);
Expand All @@ -214,7 +213,7 @@ const getBaseContentPath = (component: SourceComponent, mergeWith?: SourceCompon
const baseContentPath = component.getPackageRelativePath(component.content, 'source');
return join(dirname(baseContentPath), baseName(baseContentPath));
}
throw new SfError(`Expected a content path for ${component.name} (${component.xml ?? ''})`);
throw new SfError(`Expected a content path for ${component.name} (${component.xml ?? '<no xml>'})`);
};

const getExtensionFromType = (contentType: string): string =>
Expand Down Expand Up @@ -242,7 +241,7 @@ async function getStaticResourceZip(component: SourceComponent, content: string)
return await JSZip.loadAsync(staticResourceZip, { createFolders: true });
} catch (e) {
throw new SfError(
`Unable to open zip file ${content} for ${component.name} (${component.xml ?? ''})`,
`Unable to open zip file ${content} for ${component.name} (${component.xml ?? '<no xml>'})`,
'BadZipFile',
['Check that your file really is a valid zip archive']
);
Expand Down
4 changes: 2 additions & 2 deletions src/resolve/connectionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ const listMembers =
const inferFilenamesFromType =
(metadataType: MetadataType) =>
(member: RelevantFileProperties): RelevantFileProperties =>
typeof member.fileName === 'object'
? { ...member, fileName: `${metadataType.directoryName}/${member.fullName}.${metadataType.suffix ?? ''}` }
typeof member.fileName === 'object' && metadataType.suffix
? { ...member, fileName: `${metadataType.directoryName}/${member.fullName}.${metadataType.suffix}` }
: member;

const isNonEmptyString = (value: string | undefined): boolean => typeof value === 'string' && value.length > 0;
10 changes: 5 additions & 5 deletions src/resolve/sourceComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class SourceComponent implements MetadataComponent {
}
if (this.parent && this.type.ignoreParentName) {
if (!this.name) {
throw new SfError(`Component was initialized without a name: ${this.xml ?? ''} (${this.type.name})`);
throw new SfError(`Component was initialized without a name: ${this.xml ?? '<no xml>'} (${this.type.name})`);
}
return this.name;
} else {
Expand Down Expand Up @@ -350,17 +350,17 @@ export class SourceComponent implements MetadataComponent {
}

return Object.values(this.type.children.types).flatMap((childType) => {
const uniqueIdElement = childType.uniqueIdElement;
const { uniqueIdElement, xmlElementName } = childType;

if (!uniqueIdElement) {
if (!uniqueIdElement || !xmlElementName) {
return [];
}
const xmlPathToChildren = `${this.type.name}.${childType.xmlElementName ?? ''}`;
const xmlPathToChildren = `${this.type.name}.${xmlElementName}`;
const elements = ensureArray(get(parsed, xmlPathToChildren, []));
return elements.map((element) => {
const name = getString(element, uniqueIdElement);
if (!name) {
throw new SfError(`Missing ${uniqueIdElement} on ${childType.name} in ${this.xml ?? ''}`);
throw new SfError(`Missing ${uniqueIdElement} on ${childType.name} in ${this.xml ?? '<no xml>'}`);
}
return new SourceComponent(
{
Expand Down

2 comments on commit 53babf0

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 53babf0 Previous: d94960b Ratio
eda-componentSetCreate-linux 195 ms 187 ms 1.04
eda-sourceToMdapi-linux 2332 ms 2421 ms 0.96
eda-sourceToZip-linux 1831 ms 1822 ms 1.00
eda-mdapiToSource-linux 2850 ms 2773 ms 1.03
lotsOfClasses-componentSetCreate-linux 360 ms 348 ms 1.03
lotsOfClasses-sourceToMdapi-linux 3672 ms 3631 ms 1.01
lotsOfClasses-sourceToZip-linux 3079 ms 3054 ms 1.01
lotsOfClasses-mdapiToSource-linux 3575 ms 3484 ms 1.03
lotsOfClassesOneDir-componentSetCreate-linux 639 ms 625 ms 1.02
lotsOfClassesOneDir-sourceToMdapi-linux 6530 ms 6579 ms 0.99
lotsOfClassesOneDir-sourceToZip-linux 5716 ms 5440 ms 1.05
lotsOfClassesOneDir-mdapiToSource-linux 6325 ms 6384 ms 0.99

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 53babf0 Previous: d94960b Ratio
eda-componentSetCreate-win32 385 ms 408 ms 0.94
eda-sourceToMdapi-win32 4131 ms 4575 ms 0.90
eda-sourceToZip-win32 2739 ms 2805 ms 0.98
eda-mdapiToSource-win32 5674 ms 5912 ms 0.96
lotsOfClasses-componentSetCreate-win32 889 ms 920 ms 0.97
lotsOfClasses-sourceToMdapi-win32 7575 ms 7858 ms 0.96
lotsOfClasses-sourceToZip-win32 5292 ms 4935 ms 1.07
lotsOfClasses-mdapiToSource-win32 7635 ms 7897 ms 0.97
lotsOfClassesOneDir-componentSetCreate-win32 1498 ms 1442 ms 1.04
lotsOfClassesOneDir-sourceToMdapi-win32 13859 ms 13253 ms 1.05
lotsOfClassesOneDir-sourceToZip-win32 9182 ms 8584 ms 1.07
lotsOfClassesOneDir-mdapiToSource-win32 13883 ms 13298 ms 1.04

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.