-
Notifications
You must be signed in to change notification settings - Fork 4
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: Don't replace malformed appmap.yml #125
Conversation
src/config.ts
Outdated
const config = tryOr(() => YAML.parse(readFileSync(path, "utf8")) as unknown); | ||
const fileContent = tryOr(() => readFileSync(path, "utf8")); | ||
if (!fileContent) return; | ||
const config = tryOr(() => YAML.parse(fileContent) as unknown, { malformed: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a weird approach. Can you try {...} catch { return "malformed" }
instead? readConfigFile
would return ConfigFile | "malformed" | undefined
and you could check for that instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, at first, I thought about making it so, but later, I thought it leads to needless changes in surrounding parts and switched to this one. Now I changed it to ConfigFile | "malformed" | undefined
return.
46df1c3
to
62d0093
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave this some more thought, and I think it would be good to expand the scope a bit; in particular, this will still lead to replacing the config file on eg. EACCES
error, which can be a problem.
Perhaps readConfigFile
should just rethrow any exceptions except ENOENT
(which would return undefined
). The user can then be warned with the specific error message to make it clearer what's going on.
src/config.ts
Outdated
@@ -94,12 +97,16 @@ interface ConfigFile { | |||
name?: string; | |||
packages?: Package[]; | |||
response_body_max_length?: number; | |||
malformed?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to remove this.
Ok, If they have a config file besides that they don't want it to be replaced, they don't want to use default parameters, too. So we don't go on with the default config if it throws any exception except What about exiting when it's malformed too? |
62d0093
to
d96cf47
Compare
Yeah, perhaps you're right. Maybe we should just let the exceptions propagate and catch |
I agree. One point that makes me think is that the user should be given the opportunity to run with defaults if they struggle to fix their config file. For this, maybe we should inform them to remove (backup) or rename their config file to run with defaults. Or we can introduce a flag like |
Nah, I don't think the flag is necessary. But I like the idea of explaining the problem and indicating the possible solution, eg. with a message like Now I changed it to re-throw when malformed too, with the message above. |
d96cf47
to
d244d0c
Compare
src/config.ts
Outdated
config = YAML.parse(fileContent) as unknown; | ||
} catch (exn) { | ||
const exnMessage = | ||
exn && typeof exn == "object" && "message" in exn && typeof exn.message == "string" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just assert(isNativeError(exn))
for simplicity :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/util/tryOr.ts
Outdated
@@ -1,7 +1,7 @@ | |||
export default function tryOr<T>(fn: () => T): T | undefined { | |||
export default function tryOr<T, E = undefined>(fn: () => T, elseReturn?: E): T | E | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this change is used anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
d244d0c
to
c8a2caf
Compare
- Use defaults only when there is no config file (ENOENT). - Rethrow every other error thrown from readFileSync (ex: EACCESS). - Rethrow YAML parsing error when appmap.yml is malformed, appending an informative message.
c8a2caf
to
27d9b44
Compare
🎉 This PR is included in version 2.19.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fixes #80.