fix(configManager): rethrow errors instead of masking them as a TypeError - #1052
Open
DeepDiver1975 wants to merge 1 commit into
Open
Conversation
…rror
`loadYaml` handled failures from `repos.getContent` in a `.catch()` that
logged the error but neither rethrew nor returned a value. The awaited
expression therefore resolved to `undefined`, and the next statement
dereferenced `response.data`, so every config-read failure surfaced as:
TypeError: Cannot read properties of undefined (reading 'data')
That TypeError carries no `.status`, so the `if (e.status === 404) return
null` in the enclosing catch never matched and the real HTTP error was
lost. A missing settings file aborted the run instead of returning null,
and a 403/500 was indistinguishable from a 404.
`lib/settings.js` already rethrows from the equivalent `.catch()`; this
brings `configManager` in line with it.
Adds test/unit/lib/configManager.test.js, which had no coverage: a 404
now returns null, and a non-404 rejects with the original error object so
its status survives. Three of the seven tests fail without this change.
Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ConfigManager.loadYamlhandles a failedrepos.getContentin a.catch()that logs the error but neither rethrows nor returns a value:https://github.com/github-community-projects/safe-settings/blob/main-enterprise/lib/configManager.js#L22-L30
So the awaited expression resolves to
undefined, and the very next statement dereferencesresponse.data. Every failure to read the config file therefore surfaces as:Two consequences:
TypeErrorhas no.status, so theif (e.status === 404) return nullin the enclosingcatchnever matches and rethrows it instead. A missing settings file aborts the run rather than returningnullas the code plainly intends.CONFIG_PATH/ wrong account), 403 (permissions, rate limit) and 5xx all produce the samereading 'data'TypeError, pointing at a line that is not where anything went wrong.That error string shows up in issue reports where it obscured the actual cause — it is the error output in #782, and the same masking pattern is visible in #586. We lost about two days to it: the underlying failure was a plain 404 on the config repo, and nothing in the logs said so.
Change
Add
throw eto the.catch().lib/settings.jsalready does exactly this in its equivalent.catch():https://github.com/github-community-projects/safe-settings/blob/main-enterprise/lib/settings.js#L865-L874
so this brings
configManagerin line with the working version in the same codebase. With the fix, a 404 returnsnullthrough the existingcatch, and any other error propagates unchanged with itsstatusintact.Behaviour change worth calling out: a non-404 config read error now fails the sync with the real HTTP error instead of a
TypeError. Both abort, so nothing that used to succeed starts failing — only the reported error changes, and a 404 now correctly returnsnullinstead of aborting.Tests
lib/configManager.jshad no test file. Addedtest/unit/lib/configManager.test.js(7 tests) covering the success path, folder and symlink responses,loadGlobalSettingsYamlpath composition, and the two error paths: 404 resolves tonull, and a non-404 rejects with the original error object so itsstatussurvives.3 of the 7 fail on
main-enterprisewithout the change, withReceived message: "Cannot read properties of undefined (reading 'data')"— i.e. the suite reproduces the reported failure and then pins the fix.Node 22.12.0.