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

Wrong stack frame file path for macOS universal app #1010

Closed
3 tasks done
michalzaq12 opened this issue Nov 5, 2024 · 6 comments
Closed
3 tasks done

Wrong stack frame file path for macOS universal app #1010

michalzaq12 opened this issue Nov 5, 2024 · 6 comments
Assignees

Comments

@michalzaq12
Copy link

michalzaq12 commented Nov 5, 2024

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Electron SDK Version

4.17.0

Electron Version

30

What platform are you using?

MacOS

Link to Sentry event

No response

Steps to Reproduce

For errors coming from a macOS universal app, I get the full path in a stack trace:
Image

Correct path from non-universal app:
Image

app.getAppPath() returns the path to app.asar, but the files are located in app-arm64.asar or app-x64.asar, depending on the device architecture.

To build a universal app, I use @electron/universal with mergeASARs: false option.

Expected Result

...

Actual Result

...

@timfish
Copy link
Collaborator

timfish commented Nov 5, 2024

Have you tried the latest version of the SDK? You appear to be a full major version behind.

@getsantry getsantry bot removed the status in GitHub Issues with 👀 3 Nov 5, 2024
@timfish timfish self-assigned this Nov 6, 2024
@timfish
Copy link
Collaborator

timfish commented Nov 6, 2024

Reading through this again, it sounds like app.getAppPath() is returning the incorrect path?

@timfish
Copy link
Collaborator

timfish commented Nov 6, 2024

@michalzaq12
Copy link
Author

michalzaq12 commented Nov 6, 2024

Update
app.getAppPath() works fine (?). There is a simple js file in app.asar that imports the required files (located in app-arm64.asar or app-x64.asar, depending on the device architecture).

Here is a problem: https://github.com/getsentry/sentry-electron/blob/master/src/main/normalize.ts#L17, filename is not normalized.

Demo

// https://github.com/getsentry/sentry-javascript/blob/master/packages/utils/src/normalize.ts#L285
function normalizeUrlToBase(url: string, basePath: string): string {
    const escapedBase = basePath
      // Backslash to forward
      .replace(/\\/g, '/')
      // Escape RegExp special characters
      .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
  
    let newUrl = url;
    try {
      newUrl = decodeURI(url);
    } catch (_Oo) {
      // Sometime this breaks
    }
    return (
      newUrl
        .replace(/\\/g, '/')
        .replace(/webpack:\/?/g, '') // Remove intermediate base path
        // eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor
        .replace(new RegExp(`(file://)?/*${escapedBase}/*`, 'ig'), 'app:///')
    );
  }


const APP_PATH = 'D:\\sentry_test_app\\app.asar' // app.getAppPath()

// 1. Non-universal app => path normalized
console.log(normalizeUrlToBase('D:\\sentry_test_app\\app.asar\\dist\\main\\index.js', APP_PATH))
// app:///dist/main/index.js

// 2. Universal app => path is not normalized
console.log(normalizeUrlToBase('D:\\sentry_test_app\\app-arm64.asar\\dist\\main\\index.js', APP_PATH))
// D:/sentry_test_app/app-arm64.asar/dist/main/index.js

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Nov 6, 2024
@timfish
Copy link
Collaborator

timfish commented Nov 6, 2024

The normalisation code relies on app.getAppPath() returning the correct app root path. The issue is that @electron/universal uses a stub app that routes to arch specific apps but this means that app.getAppPath() does not return the correct path.

@michalzaq12
Copy link
Author

This has already been fixed in the latest @electron/universal. Sorry, my mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants