Skip to content

Conversation

@CurryYangxx
Copy link
Member

@CurryYangxx CurryYangxx commented Sep 20, 2024

Changes

show all the missing environment variables in request
image
image

@CurryYangxx CurryYangxx changed the title feat: missing variable improvement feat: missing variable improvement - [INS-4396] Sep 20, 2024
@CurryYangxx CurryYangxx requested a review from a team September 20, 2024 09:58
@jackkav
Copy link
Contributor

jackkav commented Sep 23, 2024

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.

@CurryYangxx
Copy link
Member Author

CurryYangxx commented Sep 24, 2024

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.

@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.

Comment on lines 284 to 301
// 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;
Copy link
Member Author

Choose a reason for hiding this comment

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

compare with template context and get all empty variables in one editor.
image

@CurryYangxx CurryYangxx force-pushed the feat/env-missing branch 2 times, most recently from a423967 to 11a6fe4 Compare September 26, 2024 02:43
@ihexxa
Copy link
Contributor

ihexxa commented Sep 26, 2024

image
Checked and did some tests, looks good.

@CurryYangxx CurryYangxx merged commit dd60c41 into develop Sep 26, 2024
@CurryYangxx CurryYangxx deleted the feat/env-missing branch September 26, 2024 11:17
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