Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better exception handling for type inference errors #3127

Merged
merged 5 commits into from
Apr 7, 2021

Conversation

brpowell
Copy link
Contributor

@brpowell brpowell commented Apr 6, 2021

What does this PR do?

Properly handles file paths when throwing TypeInfereceError exceptions. Also fixes it for when we are creating component counts in the baseDeployExecutor.

What issues does this PR fix or reference?

@W-9105085@

@brpowell brpowell requested a review from a team as a code owner April 6, 2021 23:16
* @param packageDirs Package directory paths
* @returns Relative path for the project
*/
export function getRelativeProjectPath(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to helper utils

import * as vscode from 'vscode';
import { sfdxCoreSettings } from '../../settings';

export function useBetaDeployRetrieve(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function isn't really needed anymore - it was from when we needed to detect the type before deploying or retrieving in addition to checking the setting. Now we can just check the setting. I got rid of it now because it was actually causing problems - If we couldn't infer the type here no deploy would trigger at all.

Comment on lines +12 to +23
const formattedException = new Error('Unknown Exception');
formattedException.name = e.name;

for (const { fsPath } of uris) {
const componentsForPath = ws.resolveSourceComponents(fsPath);
if (supportedTypes && componentsForPath) {
for (const component of componentsForPath) {
if (!permittedTypeNames.has(component.type.name)) {
return false;
}
}
}
if (e.name === 'TypeInferenceError') {
const projectPath = getRelativeProjectPath(
e.message.slice(0, e.message.lastIndexOf(':')),
await SfdxPackageDirectories.getPackageDirectoryPaths()
);
formattedException.message = `${projectPath}: Could not infer metadata type`;
}

return true;
return formattedException;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Convert to relative project path if it's a TypeInferenceError. Otherwise only throw the exception name with "Unknown Exception" as message.

createComponentCount,
useBetaDeployRetrieve
} from './betaDeployRetrieve';
export { createComponentCount } from './betaDeployRetrieve';
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also export formatException here so we can import it elsewhere by just using the ./utils path

@codecov
Copy link

codecov bot commented Apr 6, 2021

Codecov Report

Merging #3127 (b62761e) into release/v51.8.0 (dad503e) will decrease coverage by 0.00%.
The diff coverage is 88.46%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##           release/v51.8.0    #3127      +/-   ##
===================================================
- Coverage            76.19%   76.18%   -0.01%     
===================================================
  Files                  276      276              
  Lines                10527    10511      -16     
  Branches              1243     1236       -7     
===================================================
- Hits                  8021     8008      -13     
+ Misses                2157     2156       -1     
+ Partials               349      347       -2     
Impacted Files Coverage Δ
...cedx-vscode-core/src/commands/baseDeployCommand.ts 50.00% <33.33%> (-0.58%) ⬇️
...e-core/src/commands/forceSourceDeploySourcePath.ts 54.71% <50.00%> (ø)
...edx-vscode-core/src/commands/baseDeployRetrieve.ts 92.24% <100.00%> (+0.97%) ⬆️
...ode-core/src/commands/forceSourceDeployManifest.ts 62.50% <100.00%> (+0.96%) ⬆️
...e-core/src/commands/forceSourceRetrieveManifest.ts 59.45% <100.00%> (+1.12%) ⬆️
...ceSourceRetrieveMetadata/forceSourceRetrieveCmp.ts 69.47% <100.00%> (+1.05%) ⬆️
...core/src/commands/forceSourceRetrieveSourcePath.ts 68.18% <100.00%> (+2.27%) ⬆️
...scode-core/src/commands/util/betaDeployRetrieve.ts 100.00% <100.00%> (ø)
...alesforcedx-vscode-core/src/commands/util/index.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dad503e...b62761e. Read the comment docs.

}
}
}
if (e.name === 'TypeInferenceError') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any chance that the error message does not follow this format (e.g. : ) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only if we change the structure of the message :)

@@ -40,15 +41,15 @@ import { nls } from '../messages';
import { DeployQueue } from '../settings';
import { SfdxPackageDirectories, SfdxProjectConfig } from '../sfdxProject';
import { createComponentCount } from './util';
import { formatException } from './util/betaDeployRetrieve';
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to import this by just using ./util path

@brpowell brpowell merged commit 40c7fae into release/v51.8.0 Apr 7, 2021
@brpowell brpowell deleted the bp/updateSdrExceptions branch April 7, 2021 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants