Skip to content

Commit

Permalink
Improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
huonw committed Nov 4, 2024
1 parent 9146b1f commit b315920
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions reference_codegen/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,21 @@ function splitFirst(string, sep) {
}

/** Return a representation of arg value from the CLI. */
function deduceArgValue(displayArgs) {
function deduceArgValue(displayArgs, envVar) {
const exampleCli = displayArgs[0];

const val = exampleCli.includes("[no-]")
? "<bool>"
: splitFirst(exampleCli, "=")[1];

return val;
if (val) {
return val;
}

const args = JSON.stringify(displayArgs);
throw new Error(
`In ${envVar}, failed to deduce value formatting from example CLI instances: ${args}`
);
}

function generateTomlRepr(option, scope) {
Expand All @@ -227,7 +234,7 @@ function generateTomlRepr(option, scope) {
}

const tomlLines = [];
const val = deduceArgValue(option.display_args);
const val = deduceArgValue(option.display_args, option.env_var);

const isMap = val.startsWith('"{') && val.endsWith('}"');
const isArray = val.startsWith('"[') && val.endsWith(']"');
Expand Down

0 comments on commit b315920

Please sign in to comment.