Skip to content

fix: truncate headers/redirects in logs #4183

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

Merged
merged 1 commit into from
Feb 24, 2022

Conversation

ehmicky
Copy link
Contributor

@ehmicky ehmicky commented Feb 23, 2022

Fixes #4163

This PR re-enables #4172, but without the bug.

Also, regression tests have now been added to make sure re-enabling this PR is now safe.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

Sorry, something went wrong.

@ehmicky ehmicky added the type: bug code to address defects in shipped code label Feb 23, 2022
@ehmicky ehmicky requested a review from erezrokah February 23, 2022 17:02
@ehmicky ehmicky self-assigned this Feb 23, 2022
return netlifyConfig
const netlifyConfigA = truncateArray(netlifyConfig, 'headers')
const netlifyConfigB = truncateArray(netlifyConfigA, 'redirects')
return netlifyConfigB
Copy link
Contributor Author

@ehmicky ehmicky Feb 23, 2022

Choose a reason for hiding this comment

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

This function, cleanupConfig() is only used in code that prints the configuration object (GitHub search). It does not mutate its arguments, only return a new object. Therefore, it cannot modify the netlify.toml used in deploys.

export const logConfig = function ({ logs, netlifyConfig, debug }) {
if (!debug) {
return
}
logSubHeader(logs, 'Resolved config')
logObject(logs, cleanupConfig(netlifyConfig))
}
export const logConfigOnUpdate = function ({ logs, netlifyConfig, debug }) {
if (!debug) {
return
}
logSubHeader(logs, 'Updated config')
logObject(logs, cleanupConfig(netlifyConfig))
}
export const logConfigOnError = function ({ logs, netlifyConfig, severity }) {
if (netlifyConfig === undefined || severity === 'none') {
return
}
logMessage(logs, THEME.errorSubHeader('Resolved config'))
logObject(logs, cleanupConfig(netlifyConfig))
}

// Log `defaultConfig` option in debug mode
export const logDefaultConfig = function (defaultConfig, { logs, debug, baseRelDir }) {
if (!debug || defaultConfig === undefined) {
return
}
logSubHeader(logs, 'UI build settings')
logObject(logs, cleanupConfig({ ...defaultConfig, baseRelDir }))
}
// Log `inlineConfig` option in debug mode
export const logInlineConfig = function (initialConfig, { logs, debug }) {
if (!debug || Object.keys(initialConfig).length === 0) {
return
}
logSubHeader(logs, 'Configuration override')
logObject(logs, cleanupConfig(initialConfig))
}
// Log return value of `@netlify/config` in debug mode
export const logResult = function ({ configPath, buildDir, config, context, branch, env }, { logs, debug }) {
if (!debug) {
return
}
logSubHeader(logs, 'Resolved build environment')
logObject(logs, { configPath, buildDir, context, branch, env: cleanupEnvironment(env) })
logSubHeader(logs, 'Resolved config')
logObject(logs, cleanupConfig(config))
}

@ehmicky ehmicky merged commit 2471c49 into main Feb 24, 2022
@ehmicky ehmicky deleted the fix/truncate-headers-redirects-log branch February 24, 2022 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failing builds should truncate large config logs
2 participants