-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: missing variable improvement - [INS-4396] #7981
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
Conversation
64d56c0 to
f7c940d
Compare
|
On a related note, in order to feedback useful context to a CLI user, we may want to change how we handle these. Theres a ticket to address it here INS-4142, provided this PR doesn't make that any more difficult it should be fine. |
f047d72 to
fe7ae39
Compare
@jackkav This PR just get all missing variable at once and change some UI, will not affect the original error handling. So I think this will not let it more difficult. |
547ce2c to
33a0645
Compare
| // because nunjucks only report the first error, we need to extract all missing variables that are not present in the context | ||
| // for example, if the text is `{{ a }} {{ b }}`, nunjucks only report `a` is missing, but we need to report both `a` and `b` | ||
| export function extractVariableKey(text: string = '', templatingContext: Record<string, any>): string[] { | ||
| const regexVariable = /{{\s*([^ }]+)\s*}}/g; | ||
| const missingVariables: string[] = []; | ||
| let match; | ||
|
|
||
| while ((match = regexVariable.exec(text)) !== null) { | ||
| let variable = match[1]; | ||
| if (variable.includes('_.')) { | ||
| variable = variable.split('_.')[1]; | ||
| } | ||
| // Check if the variable is not present in the context | ||
| if (_.get(templatingContext, variable) === undefined) { | ||
| missingVariables.push(variable); | ||
| } | ||
| } | ||
| return missingVariables; |
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.
a423967 to
11a6fe4
Compare
11a6fe4 to
b784c04
Compare


Changes
show all the missing environment variables in request

