import{getLineColLocation as f,isAbsoluteUrl as m}from"@redocly/openapi-core";import g from"node:path";import{gray as s}from"../../tools/notifiers/helpers/colors.js";import{getCodeframe as h}from"../../utils/codeframes/codeframes.js";async function P(o,c){const e=o.location?.[0];if(!e)return`${o.message} at `;if(!e.source){const t=e.pointer??"";return`${o.message} at ${t}`}const n=m(e.source.absoluteRef)?e.source.absoluteRef:g.relative(c,e.source.absoluteRef);try{const t=f(e),i=e.pointer?s(`at ${e.pointer}`):"",l=`${n}:${t.start.line}:${t.start.col}`;let r="";try{const a=e.source?.getLines()??[],u={start:{line:t.start.line,character:t.start.col},end:{line:t.end?.line??t.start.line,character:t.end?.col??Math.max(t.start.col+1,a[t.start.line-1]?.length??t.start.col)},lines:a},{frame:$}=h(u,!0);r=$}catch{r=""}return`${l} ${i}
${o.message}
${r?`${r}
`:""}`}catch{const t=e.pointer?s(`at ${e.pointer}`):"";return`${n} ${t}
${o.message}`}}export{P as formatBundleError};
