MCPcopy
hub / github.com/prisma/prisma / EnabledCallSite

Class EnabledCallSite

packages/client/src/runtime/utils/CallSite.ts:30–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30export class EnabledCallSite implements CallSite {
31 private _error: Error
32 constructor() {
33 this._error = new Error()
34 }
35 getLocation(): LocationInFile | null {
36 const stack = this._error.stack
37 if (!stack) {
38 return null
39 }
40 const stackFrames = stackTraceParser.parse(stack)
41 // TODO: more resilient logic to check that it's not relative to cwd
42 const frame = stackFrames.find((t) => {
43 // Here we are trying to find the location in the user's code which caused the error
44 if (!t.file) {
45 return false
46 }
47
48 // convert windows path to posix path
49 const posixFile = pathToPosix(t.file)
50 return (
51 posixFile !== '<anonymous>' && // Ignore as we can not read an <anonymous> file
52 !posixFile.includes('@prisma') && // Internal, unbundled code
53 !posixFile.includes('/packages/client/src/runtime/') && // Runtime sources when source maps are used
54 !posixFile.endsWith('/runtime/client.js') && // Bundled runtimes
55 !posixFile.startsWith('internal/') && // We don't want internal nodejs files
56 !t.methodName.includes('new ') && // "new CallSite" call and maybe other constructors
57 !t.methodName.includes('getCallSite') && // getCallSite function from this module
58 !t.methodName.includes('Proxy.') && // Model proxies
59 t.methodName.split('.').length < 4
60 )
61 })
62
63 if (!frame || !frame.file) {
64 return null
65 }
66
67 return {
68 fileName: frame.file,
69 lineNumber: frame.lineNumber,
70 columnNumber: frame.column,
71 }
72 }
73}
74
75export function getCallSite(errorFormat: ErrorFormat): CallSite {
76 if (errorFormat === 'minimal' || TARGET_BUILD_TYPE === 'wasm-compiler-edge') {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected