Skip to content

Conversation

@robertbrignull
Copy link
Contributor

This PR aims to make the parsing of the config file stricter, and safer from a code maintenance point of view.

The changes are:

  • Improve error messages to be more descriptive.
  • Throw an error if any field is of a type that it shouldn't be, instead of silently ignoring it.
  • Define constants for all the field names and always use those constants when accessing that field.

This is obviously going to conflict a bit with #45 but it shouldn't be too bad and it'll be easy to sort out whichever one gets merged first.

Merge / deployment checklist

  • Run test builds as necessary. Can be on this repository or elsewhere as needed in order to test the change - please include links to tests in other repos!
    • CodeQL using init/analyze actions
    • 3rd party tool using upload action
  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.

@robertbrignull robertbrignull changed the title make config file parsing more strict Make config file parsing more strict May 26, 2020
@robertbrignull
Copy link
Contributor Author

@sampart would you be ok taking on review of this PR? However @Daverlo, @anaarmas, and @joshhale you should probably keep an eye on this too though for the reasons I explain below.

The main goal here is making the config parsing give more helpful error messages in the case of incorrect input. A side product is throwing an error on any invalid input instead of silently ignoring it in some cases. This is therefore technically not backwards compatible, however only in that it enforces the schema we've already published. I personally think it can still go on the v1 branch and this change is not dramatic enough or likely enough to cause problems that we should change it or hold it back or start a new branch.

@robertbrignull robertbrignull assigned sampart and unassigned Daverlo Jun 8, 2020
Copy link
Contributor

@sampart sampart left a comment

Choose a reason for hiding this comment

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

Looks good to me! Just some very minor wording tweaks.

}

export function getPathsIgnoreInvalid(configFile: string): string {
return getConfigFilePropertyError(configFile, PATHS_IGNORE_PROPERTY, 'must be an array of non-empty string');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return getConfigFilePropertyError(configFile, PATHS_IGNORE_PROPERTY, 'must be an array of non-empty string');
return getConfigFilePropertyError(configFile, PATHS_IGNORE_PROPERTY, 'must be an array of non-empty strings');

'), a relative path, or of the form owner/repo@ref\n' +
'Found: ' + queryUses;
export function getPathsInvalid(configFile: string): string {
return getConfigFilePropertyError(configFile, PATHS_PROPERTY, 'must be an array of non-empty string');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return getConfigFilePropertyError(configFile, PATHS_PROPERTY, 'must be an array of non-empty string');
return getConfigFilePropertyError(configFile, PATHS_PROPERTY, 'must be an array of non-empty strings');

return getConfigFilePropertyError(
configFile,
QUERIES_PROPERTY + '.' + QUERIES_USES_PROPERTY,
'is invalid as the local path "' + localPath + '" is output of the repository');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'is invalid as the local path "' + localPath + '" is output of the repository');
'is invalid as the local path "' + localPath + '" is outside of the repository');

@robertbrignull
Copy link
Contributor Author

Thanks for spotting all those 👍

@robertbrignull robertbrignull merged commit a9de5b5 into master Jun 9, 2020
@github-actions github-actions bot mentioned this pull request Jun 15, 2020
@robertbrignull robertbrignull deleted the safe-config-parsing branch June 15, 2020 08:56
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.

4 participants