Files
cypress/packages/server/lib/cloud/artifacts/protocol_artifact.ts
T
Cacie Prins fc88764ad5 feat: more informative error messages when Test Replay fails to capture (#29312)
* new error messages

* errors for initialization and capturing test replay

* messaging the case where no protocol instance but also no fatal error

* adds suggested remedies to initialization errors

* differentiation between network and http errors, initial work on db missing error

* improve db not found error

* add new error type to schema

* rm commented dead code

* clean up network error creation in uploadStream

* make artifact confirmation error msg more general

* test display of put instance artifacts failure

* changelog

* ensure we are displaying errors even in quiet mode

* fix pending changelog

* new snapshots for protocol errors

* improve aggregate error

* resolved html error snapshots

* fix check-ts

* fix test

* sanitize temp dir in CLOUD_PROTOCOL_CAPTURE_FAILURE error msg

* changelog

* fix double entry of certain network errors, error message prop for network errors

* fix url arg for network error

* Update packages/server/lib/cloud/artifacts/upload_artifacts.ts

Co-authored-by: Ryan Manuel <ryanm@cypress.io>

* rm extra formatting from debug

* snapshot whitespace

* changelog update

* +pending

* Update cli/CHANGELOG.md

* resolve snapshots?

* does moving the stack trace fix whitespace in snapshots in ci?

* maybe fixes whitespace on electron now?

* fully normalize stack traces

* remove full normalization

* maybe debug stack normalization

* rm stack traces from error messages

---------

Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
Co-authored-by: Ryan Manuel <ryanm@cypress.io>
2024-05-01 14:32:53 -04:00

78 lines
2.4 KiB
TypeScript

import fs from 'fs/promises'
import { existsSync } from 'fs'
import type { ProtocolManager } from '../protocol'
import { IArtifact, ArtifactUploadStrategy, ArtifactUploadResult, Artifact, ArtifactKinds } from './artifact'
import Debug from 'debug'
const debug = Debug('cypress:server:cloud:artifacts:protocol')
interface ProtocolUploadStrategyResult {
success: boolean
fileSize: number | bigint
specAccess: {
offset: number
size: number
}
}
const createProtocolUploadStrategy = (protocolManager: ProtocolManager) => {
const strategy: ArtifactUploadStrategy<Promise<ProtocolUploadStrategyResult | {}>> =
async (filePath, uploadUrl, fileSize) => {
const fatalError = protocolManager.getFatalError()
if (fatalError) {
throw fatalError.error
}
const res = await protocolManager.uploadCaptureArtifact({ uploadUrl, fileSize, filePath })
return res ?? {}
}
return strategy
}
export const createProtocolArtifact = async (filePath: string, uploadUrl: string, protocolManager: ProtocolManager): Promise<IArtifact | undefined> => {
let size: number | undefined
debug('statting file path', filePath)
try {
const stat = await fs.stat(filePath)
debug('file stat', stat)
size = stat.size
} catch (e) {
debug('failed to stat protocol artifact filepath: ', e)
protocolManager.addFatalError('uploadCaptureArtifact', new Error(`File not found: ${filePath}`))
}
return size !== undefined ? new Artifact('protocol', filePath, uploadUrl, size, createProtocolUploadStrategy(protocolManager)) : undefined
}
export const composeProtocolErrorReportFromOptions = async ({
protocolManager,
protocolCaptureMeta,
captureUploadUrl,
}: {
protocolManager?: ProtocolManager
protocolCaptureMeta: { url?: string, disabledMessage?: string }
captureUploadUrl?: string
}): Promise<ArtifactUploadResult> => {
const url = captureUploadUrl || protocolCaptureMeta.url
const pathToFile = protocolManager?.getArchivePath()
const fileSize = pathToFile && existsSync(pathToFile) ? (await fs.stat(pathToFile))?.size : 0
const fatalError = protocolManager?.getFatalError()
debug('fatalError via composeProtocolErrorReport', fatalError)
return {
key: ArtifactKinds.PROTOCOL,
url: url ?? 'UNKNOWN',
pathToFile: pathToFile ?? 'UNKNOWN',
fileSize,
success: false,
error: fatalError?.error.message || 'UNKNOWN',
errorStack: fatalError?.error.stack || 'UNKNOWN',
}
}