import{Ai as s,Oi as k,ki as b,kt as h,rt as u,y as g}from"./cells-CJLUCcQg.js";import{i as D}from"./strings--BknHX9C.js";function H(t){if(b(t.mimetype)){if(!Array.isArray(t.data))return null;let e=t.data.filter(r=>!r.type.includes("ancestor"));return e.length===0?null:{errorData:e}}return s(t.mimetype)?typeof t.data!="string"||t.data.length===0?null:{errorData:[],tracebackHtml:t.data}:null}function T(t){return t.some(e=>"traceback"in e&&e.traceback)}function w(t){let e=t==null?void 0:t.find(r=>s(r.mimetype));if(!(!e||typeof e.data!="string"||e.data.length===0))return e.data}function x(t,e){if(t.tracebackHtml)return t.tracebackHtml;if(!T(t.errorData))return w(e)}function A(t){let{cellIds:e,cellRuntime:r,cellData:n}=t.get(g),i=[];for(let[f,a]of e.inOrderIds.entries()){let o=r[a],c=o.output;if(!c||!k(c.mimetype))continue;let l=H(c);if(!l)continue;let d=h(n[a].name,f),y=n[a].lastCodeRun??n[a].code;i.push({cellId:a,cellName:d,cellCode:y,errorData:l.errorData,tracebackHtml:x(l,o.consoleOutputs)})}return i}function p(t){return t.type==="setup-refs"?"The setup cell cannot have references":t.type==="cycle"?"This cell is in a cycle":t.type==="multiple-defs"?`The variable '${t.name}' was defined by another cell`:t.type==="import-star"||t.type==="ancestor-stopped"||t.type==="ancestor-prevented"||t.type==="exception"||t.type==="strict-exception"?t.msg:t.type==="interruption"?"This cell was interrupted and needs to be re-run":t.type==="syntax"||t.type==="unknown"||t.type==="sql-error"?t.msg:t.type==="internal"?t.msg||"An internal error occurred":(D(t),"Unknown error")}function m(t){let e=p(t);return"traceback"in t&&t.traceback&&(e+=`

Traceback:
${u(t.traceback)}`),e}function v(t){let e=[t.cellName];return t.tracebackHtml&&e.push(u(t.tracebackHtml)),t.errorData.length>0&&e.push(t.errorData.map(m).join(`

`)),e.join(`

`)}export{A as i,v as n,m as r,p as t};
