getsentry / sentry-javascript-bundler-plugins

JavaScript Bundler Plugins for Sentry
https://sentry.io
BSD 3-Clause "New" or "Revised" License
141 stars 36 forks source link

Vite production build failed due to SENTRY_RELEASE containing double quotes #584

Closed kenn closed 3 months ago

kenn commented 3 months ago

Environment

Latest everything

Steps to Reproduce

  1. Set git commit as release string with process.env.SENTRY_RELEASE = execSync('git log -1 --pretty=%B')
  2. Get error on production build with a following error:
_global.SENTRY_RELEASE={id:"commit containing "double quotes""};

Expected Result

If it's stored in a JSON, double quotes should be escaped appropriately.

Actual Result

Image

lforst commented 3 months ago

Thanks for reporting. We should fix this. I wonder though whether Sentry itself supports quotes in releases. In any case this should probably not crash the build though.

lforst commented 3 months ago

Small note though: You're assigning a buffer to process.env. SENTRY_RELEASE which is probably not the best idea 😄 Maybe do .toString() or decode as utf8 so that it becomes a string.

kenn commented 3 months ago

Thanks for the quick fix!

That was for reporting abbreviation and this was the actual code, for anyone who finds it useful.

// Get the git info
const DATE = execSync(
  "git log -1 --date=format:'%Y-%m-%d' --pretty=format:'%ad'",
)
  .toString()
  .trim()
const MESSAGE = execSync('git log -1 --pretty=%B')
  .toString()
  .trim()
  .split('\n')[0]
  .slice(0, 20)
const HASH = execSync('git rev-parse --short HEAD').toString().trim()
process.env.SENTRY_RELEASE = `${DATE} ${MESSAGE} - ${HASH}`