Skip to content
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

List of known sourcemap inject bugs #1647

Closed
3 tasks done
loewenheim opened this issue Jun 16, 2023 · 17 comments
Closed
3 tasks done

List of known sourcemap inject bugs #1647

loewenheim opened this issue Jun 16, 2023 · 17 comments
Assignees

Comments

@loewenheim
Copy link
Contributor

loewenheim commented Jun 16, 2023

  1. We have gotten customer reports of injection problems when a file starts with something like
(this.foo=this.bar||[]).push([[2],[function(e,t,n){"use strict"; [] }

This trips the "use pragma" detection and causes the line to be skipped, which is obviously not intended. Solution: make the regex stricter.

  1. Block comments aren't handled at all. Thus, if a file started with
/* lol, lmao */
"use strict";

we would erroneously inject at the very top. Solution: handle block comments.

  1. 'use strict'; can be on the same line as the rest of the code, eg 'use strict';(function(){console.log('wat')})(); is a valid code, and we do not handle injecting snippet "in-between" - ref: Source maps inject results in corrupt source map files #1646

Tasks

  1. loewenheim
@loewenheim loewenheim self-assigned this Jun 16, 2023
@kamilogorek kamilogorek changed the title Injection bugs involving block comments & use pragmas List of known sourcemap inject bugs Jun 19, 2023
@yharaskrik
Copy link

yharaskrik commented Jul 4, 2023

I have something to add to this list. We are using GraphQL and sometimes the injection gets injected into the template string that is defining out GraphQL queries. Here is a couple snippets to show you:

image
image
Although this MIGHT fall into #1 above.

This is a minified Angular App

@loewenheim
Copy link
Contributor Author

Thank you for the report. The second screenshot looks gnarly. The fact that a statement starts on the same line as the pragma and then continues for several lines is going to be very hard to work around.

@yharaskrik
Copy link

Thank you for the report. The second screenshot looks gnarly. The fact that a statement starts on the same line as the pragma and then continues for several lines is going to be very hard to work around.

Is that not normal? I don't think we are doing anything different than a normal Angular production build. I can investigate a bit to see if maybe we are doing something out of the norm?

@loewenheim
Copy link
Contributor Author

Is that not normal? I don't think we are doing anything different than a normal Angular production build. I can investigate a bit to see if maybe we are doing something out of the norm?

Sorry, I didn't mean to imply you were doing anything wrong. This is just one of several assumptions we were making that appear to not hold up in practice.

@yharaskrik
Copy link

Is that not normal? I don't think we are doing anything different than a normal Angular production build. I can investigate a bit to see if maybe we are doing something out of the norm?

Sorry, I didn't mean to imply you were doing anything wrong. This is just one of several assumptions we were making that appear to not hold up in practice.

No worries all good! I can double check that a plain angular build that is freshly generated does the same thing just so we know.

@yharaskrik
Copy link

Is that not normal? I don't think we are doing anything different than a normal Angular production build. I can investigate a bit to see if maybe we are doing something out of the norm?

Sorry, I didn't mean to imply you were doing anything wrong. This is just one of several assumptions we were making that appear to not hold up in practice.

No worries all good! I can double check that a plain angular build that is freshly generated does the same thing just so we know.

Just generate a fresh Angular project using Nx, looks like the apps get minified to a single line. So ya. I guess that is a case you might have to handle. Let me know if I can help at all.

@loewenheim
Copy link
Contributor Author

@j-fulbright Does the first line of the injected JS file contain "use strict"; or something similar?

@j-fulbright
Copy link

j-fulbright commented Jul 6, 2023

Actually after reviewing with another developer, it was determined the CLI is adding an extraneous semicolon in the mappings group. Reviewing of the source for the CLI, it appears this is intentional in some way, but it is breaking our sourcemaps, as removing the semicolon, makes them resolve correctly on the commandline.

*mappings = format!(";{mappings}");

Working:

{"version":3,"file":"main.2de0db9ef2b6b37e.js","mappings":"uIAAO

After CLI:

"file":"main.2de0db9ef2b6b37e.js","mappings":";uIAAO,IAAMA

Beginning of some of the JS files:

(self.webpackChunkcorporate_portal=self.webpackChunkcorporate_portal||[]).push([[179],{7177:(Xt,rt,B)=>{"use strict";B.d(rt,{$:()=>s});let s=(()=>{class X{}return X.paths={base:"",login:"login",portal:"secure",dashboard:"dashboard",users:"users",groups:"groups",accounts:"accounts",phoneSearchLink:"phone-search-link",dataSearch:"data-search",dataValidation:"data-validation",generatedReports:"generated-reports",

It is possible the pragma changes that are merged may resolve for us, since it changes regex as well

@d3ce1t
Copy link

d3ce1t commented Jul 19, 2023

As a workaround, I'm executing this in a React App in order to remove the semicolon in sourcemaps after injecting debugIds using sentry-cli:

find build/static/js -type f -name "*.js.map" -exec sed -i 's/\("mappings":"\);/\1/g' {} +

I hope it works for you :)

@loewenheim
Copy link
Contributor Author

I am sorry for the frustration caused by this. We're currently working on putting injection on a more solid foundation.

@jbub
Copy link

jbub commented Jul 20, 2023

We just got bit by this badly, simplified reproducer:

Original js file:

(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
        typeof define === 'function' && define.amd ? define(factory) :
            (global = global || self, global.myObject = factory());
}(this, (function () { 'use strict';
    var myHTML = "\n";
    return {};
})));

Minified:

(()=>{var i=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var d=i((t,f)=>{(function(n,e){typeof t=="object"&&typeof f<"u"?f.exports=e():typeof define=="function"&&define.amd?define(e):(n=n||self,n.myObject=e())})(t,function(){"use strict";var n=`
`;return{}})});d();})();

Debug ids Injected:

(()=>{var i=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var d=i((t,f)=>{(function(n,e){typeof t=="object"&&typeof f<"u"?f.exports=e():typeof define=="function"&&define.amd?define(e):(n=n||self,n.myObject=e())})(t,function(){"use strict";var n=`
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2c4f8e42-99ad-5954-85ef-815190b8286a")}catch(e){}}();
`;return{}})});d();})();
//# debugId=2c4f8e42-99ad-5954-85ef-815190b8286a

As you can see this is pretty bad, it ends up inserting the sentry debug snippet inside the myHTML variable. Are there any workarounds available ? When can we expect this to be fixed ? We had to disable sourcemap support because of this, making the Sentry issues mostly unreadable.

@kamilogorek
Copy link
Contributor

Adding #1689 to the list to make it easier to track.

@jbub
Copy link

jbub commented Jul 20, 2023

@kamilogorek this was closed by mistake ?

@kamilogorek
Copy link
Contributor

Yes, sorry. Thanks for catching this. I meant to close linked issue only 😅

@loewenheim
Copy link
Contributor Author

All of these bugs should be fixed as of sentry-cli 2.20.4. Thank you very much for your forbearance, eveyone 🙇

@NSiggel
Copy link

NSiggel commented Aug 19, 2023

not sure if related, but we are having an issue where using "sentry-cli sourcemaps inject" has broken our projects use of the Angular SwUpdate.versionUpdates.subscribe((event: VersionEvent)
to run automatic updates in our application in production.

As soon as we removed the

  • sentry-cli sourcemaps inject $CODEBUILD_SRC_DIR/www

The next release went through automatic updates properly.

I suspect this is causing an issue for the ServiceWorker process looking up which files need to be downloaded (hashmap lookup ?) such that the inject process breaks the hashmap of files to be downloaded by the updater ?

ANY suggestions/work arounds ? I was happy to finally get proper source maps for a release working w/ Web/iOS Capacitor via the artifact bundles but now need to remove it from our CICD since broke automatic updates.

@lforst
Copy link
Member

lforst commented Aug 28, 2023

@NSiggel To me this doesn't sound like a bug. If injecting something into your code is not feasible due to code integrity you should probably resort to the legacy method of uploading which does not need to inject but is a bit trickier to get right.

If you face any more issues please open another issue since this seems unrelated.

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

No branches or pull requests

8 participants