Files
cypress/packages/data-context/src/sources/ErrorDataSource.ts
T
Cacie Prins 6b9f27c95d dependency: electron@36.4.0 (#31912)
* dependency: update Electron to 34

* setup workflows to run against binary branch and on all tests

* changelog entry

* node version did bump minorly

* Update base-internal image to match new node version

* fix typo

* changelog updates

* bumping to newest version just released today - hopefully solves glibc error

* fix cy in cy

* remove extra register_ts_node require

* updated lockfile

* upgrade better-sqlite3

* changelog

* update electron in top level package.json

* ts issue, update to use binary workflow for e35, update ancillary deps

* update gh issue templates

* bump missed image names and engines field

* node 22

* snapgen?

* ts issue, log errors even if err.stderr/stdout is null

* more logging

* defer http-proxy common.js due to regexp issue in v8 13.4.* - 13.8.91

* update images for node 22.15.1, use bullseye instead of buster for bettersqlite

* use bullseye image for glibc2.31 build of bettersqlite

* use electron-36 publish binary branch

* node-abi update, set http-proxy deferred in darwin

* update .node-version

* attempt to patch http-proxy to immediately defer  http-proxy/lib/http-proxy/common.js

* empty commit [run ci]

* better patch?

* changelog

* changelog

* Updates v8 snapshots to fix windows build (#31918)

* use node 22 in the v8 snapshot update workflow

* index on windows-v8-snapshots: a013464197 use node 22 in the v8 snapshot update workflow

* index on windows-v8-snapshots: a013464197 use node 22 in the v8 snapshot update workflow

* index on windows-v8-snapshots: a013464197 use node 22 in the v8 snapshot update workflow

* run workflows on windows/mac

---------

Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com>

* update protocol system test snapshots (#31925)

* use snapshot to verify the error message on invalid json (#31926)

* chore: account for all node: internal stacks when trying to calculate the code frame. Accounts additionally for node:diagnostics_channel (#31935)

* Fixes electron 36 integrity checks (#31956)

* update the fs.readFileSync integrity check expectation

* maybe this fn is missing from the expected stack?

* more debug, change the stack up a little

* actual fn name is traceSync

* logging

* logging

* remove logging from integrity check

* maybe circle api changed?

* correct params

* inspect stack frames for differences

* have to manually serialize the stack frames

* change expectation

* update expected global keys

* additional allow list

* update key allow list

* increase zipfile size limit on non-windows builds

* revert logging changes

* Update scripts/binary/binary-integrity-check-source.js

* increase timeout to 120s for darwin fsevents/native module test (#31975)

* print out stdout for darwin test

* try and fix test

* update readme re: browsers-internal images, ensure module_api_spec binary test uses correct electron version

* Update .circleci/workflows.yml

Co-authored-by: Bill Glesias <bglesias@gmail.com>

* Update .circleci/workflows.yml

Co-authored-by: Bill Glesias <bglesias@gmail.com>

* trigger 15.0.0 binary pipeline rather than electron-36 specific one

* Update cli/CHANGELOG.md

Co-authored-by: Bill Glesias <bglesias@gmail.com>

* Update cli/CHANGELOG.md

---------

Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
Co-authored-by: Ryan Manuel <ryanm@cypress.io>
Co-authored-by: Jennifer Shehane <shehane.jennifer@gmail.com>
Co-authored-by: cypress-bot[bot] <+cypress-bot[bot]@users.noreply.github.com>
Co-authored-by: Bill Glesias <bglesias@gmail.com>
2025-07-07 13:03:13 -04:00

76 lines
2.6 KiB
TypeScript

import { ErrorWrapperSource, stackUtils } from '@packages/errors'
import path from 'path'
import _ from 'lodash'
import { codeFrameColumns } from '@babel/code-frame'
import os from 'os'
import type { DataContext } from '..'
const tsxCodeFrameFilter = '/node_modules/tsx/dist/register'
const windowsTsxCodeFrameFilter = tsxCodeFrameFilter.replaceAll('/', '\\')
const isWindows = os.platform() === 'win32'
export interface CodeFrameShape {
line: number
column: number
absolute: string
codeBlock: string
}
export class ErrorDataSource {
constructor (private ctx: DataContext) {}
isUserCodeError (source: ErrorWrapperSource) {
return Boolean(source.cypressError.originalError && !source.cypressError.originalError?.isCypressErr)
}
async codeFrame (source: ErrorWrapperSource): Promise<CodeFrameShape | null> {
if (!this.ctx.currentProject || !this.isUserCodeError(source)) {
return null
}
// If we saw a TransformError, or a esbuild error we will extract the error location from the message
const compilerErrorLocation = source.cypressError.originalError?.compilerErrorLocation
let line: number | null | undefined
let column: number | null | undefined
let absolute: string | null | undefined
if (compilerErrorLocation) {
line = compilerErrorLocation.line
column = compilerErrorLocation.column
absolute = path.join(this.ctx.currentProject, compilerErrorLocation.filePath)
} else {
// Skip any stack trace lines which come from node:internal code
const stackLines = stackUtils.getStackLines(source.cypressError.stack ?? '')
// we want to filter out any tsx transformation code in the stack to help identify the error. Windows stack can have both posix paths and dos paths so we need to filter both (last line is a no-op on posix as its the same thing)
const filteredStackLines = stackLines.filter((stackLine) => !stackLine.includes('node:') && !stackLine.includes('source-map-support') && !stackLine.includes(tsxCodeFrameFilter) && !(isWindows && stackLine.includes(windowsTsxCodeFrameFilter)))
const parsedLine = stackUtils.parseStackLine(filteredStackLines[0] ?? '')
if (parsedLine) {
absolute = parsedLine.absolute
line = parsedLine.line
column = parsedLine.column
}
}
if (!absolute || !_.isNumber(line) || !_.isNumber(column)) {
return null
}
const codeBlock = codeFrameColumns(await this.ctx.fs.readFile(absolute, 'utf8'), {
start: { line, column },
}, {
linesAbove: 2,
linesBelow: 4,
})
return {
absolute,
line,
column,
codeBlock,
}
}
}