MCPcopy
hub / github.com/vitejs/vite / _formatLog

Method _formatLog

packages/vite/src/node/server/pluginContainer.ts:919–1019  ·  view source on GitHub ↗
(
    e: string | E,
    position?: number | { column: number; line: number },
  )

Source from the content-addressed store, hash-verified

917 }
918
919 private _formatLog<E extends RollupLog>(
920 e: string | E,
921 position?: number | { column: number; line: number },
922 ): E {
923 const err = (typeof e === 'string' ? new Error(e) : e) as E
924 if (err.pluginCode) {
925 return err // The plugin likely called `this.error`
926 }
927 err.plugin = this._plugin.name
928 if (this._activeId && !err.id) err.id = this._activeId
929 if (this._activeCode) {
930 err.pluginCode = this._activeCode
931
932 // some rollup plugins, e.g. json, sets err.position instead of err.pos
933 const pos = position ?? err.pos ?? (err as any).position
934
935 if (pos != null) {
936 let errLocation
937 try {
938 errLocation = numberToPos(this._activeCode, pos)
939 } catch (err2) {
940 this.environment.logger.error(
941 colors.red(
942 `Error in error handler:\n${err2.stack || err2.message}\n`,
943 ),
944 // print extra newline to separate the two errors
945 { error: err2 },
946 )
947 throw err
948 }
949 err.loc = err.loc || {
950 file: err.id,
951 ...errLocation,
952 }
953 err.frame = err.frame || generateCodeFrame(this._activeCode, pos)
954 } else if (err.loc) {
955 // css preprocessors may report errors in an included file
956 if (!err.frame) {
957 let code = this._activeCode
958 if (err.loc.file) {
959 err.id = normalizePath(err.loc.file)
960 try {
961 code = fs.readFileSync(err.loc.file, 'utf-8')
962 } catch {}
963 }
964 err.frame = generateCodeFrame(code, err.loc)
965 }
966 } else if ((err as any).line && (err as any).column) {
967 err.loc = {
968 file: err.id,
969 line: (err as any).line,
970 column: (err as any).column,
971 }
972 err.frame = err.frame || generateCodeFrame(this._activeCode, err.loc)
973 }
974
975 // TODO: move it to overrides
976 if (

Callers 4

debugMethod · 0.95
infoMethod · 0.95
warnMethod · 0.95
errorMethod · 0.95

Calls 5

numberToPosFunction · 0.90
generateCodeFrameFunction · 0.90
normalizePathFunction · 0.90
_getCombinedSourcemapMethod · 0.80
errorMethod · 0.65

Tested by

no test coverage detected