Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

type: publish the refusal for the shell loader, so its card is not painted over type's message (#767)

nyblnet82a3c65757b5
diff --git a/scripts/test-type-cantopen-browser.mjs b/scripts/test-type-cantopen-browser.mjs
index e7c51308..ccdac937 100644
--- a/scripts/test-type-cantopen-browser.mjs
+++ b/scripts/test-type-cantopen-browser.mjs
@@ -19,11 +19,15 @@
// handler's sentinel never fires;
//
// - no text from the file appears anywhere outside that message; type's
-// boot error is a fixed sentence, since the detail is already on screen.
+// boot error is a fixed sentence, since the detail is already on screen;
+// - type publishes window.bento = { format, refused: true } (the shell
+// loader's contract for "painted its own refusal"), so the page shows ONE
+// message: the app does not run again on a later loader path, and no
+// "This file could not start" card is painted over it.
//
// Mutations (run, judged by exit code): set the detail line with innerHTML
// instead of textContent → red; put the detail back into the thrown error
-// → red.
+// → red; drop the published refusal → red.
import { readFileSync, writeFileSync, mkdtempSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
@@ -64,12 +68,17 @@ try {
detail: card?.querySelectorAll('p')[0]?.textContent ?? '',
fromFile: document.querySelectorAll('body img, body b').length,
fired: window.__fired === 1,
+ published: JSON.stringify({ format: window.bento?.format, refused: window.bento?.refused, doc: !!window.bento?.doc }),
+ messages: [...document.querySelectorAll('h1')].filter((h) => h.textContent === 'This file could not be opened').length,
+ startCard: document.body.textContent.includes('This file could not start'),
// everything on the page outside type's own message
outside: [...document.body.querySelectorAll('*')].filter((e) => !card?.contains(e) && !e.contains(card) && !e.closest('script, style'))
.map((e) => e.textContent).join(' '),
}
})
ok(r.shown, `${c.name}: the can't-open message is shown`)
+ ok(r.published === '{"format":"bento/type","refused":true,"doc":false}', `${c.name}: the refusal is published for the shell loader (${r.published})`)
+ ok(r.messages === 1 && !r.startCard, `${c.name}: exactly one message, and no "could not start" card over it (${r.messages} message(s), start card ${r.startCard})`)
if (c.literal) ok(r.detail.includes(c.literal), `${c.name}: the detail reads as literal text ("${r.detail.slice(0, 70)}")`)
ok(!/onerror|__fired|<img|<b>|bold/.test(r.outside),
`${c.name}: no text from the file appears anywhere outside the message`)
diff --git a/type/src/main.ts b/type/src/main.ts
index 9b088748..c8991cef 100644
--- a/type/src/main.ts
+++ b/type/src/main.ts
@@ -17,7 +17,7 @@ import './registry.ts'; // side-effect: every feature module registers itself
import { i18nApi } from '../../kernel/src/i18n.ts';
import { openAbout } from './about.ts';
import { startTheme, setTheme, themeChoice, type ThemeChoice } from '../../kernel/src/theme.ts';
-import { parseDoc, emptyDoc, uid, wordCount, withoutEmbeddedCaps, type TypeDoc } from './model.ts';
+import { parseDoc, emptyDoc, uid, wordCount, withoutEmbeddedCaps, FORMAT, type TypeDoc } from './model.ts';
import { gateRestored } from './restoregate.ts';
import { Store } from './store.ts';
import { keepLiveHistory } from './docclass.ts';
@@ -102,7 +102,17 @@ if (parsed.ok) {
line('p', parsed.detail);
line('p', 'Nothing has been changed. Close this tab rather than saving over it.', 'color:#8d95a3');
document.body.replaceChildren(card);
- // A FIXED message: whatever reports this error may not treat it as text, and
+ // Tell the shell loader this was a deliberate refusal, not a failed start
+ // (its contract: { doc } running, { locked } at a password gate, { refused }
+ // painted its own refusal). Without it the loader counts the throw below as
+ // a path that failed, tries the next, and paints "This file could not
+ // start" over this message. bento/type has no password gate, so an
+ // encrypted file lands here too. Guarded by
+ // scripts/test-type-cantopen-browser.mjs.
+ (window as unknown as { bento: unknown }).bento = { format: FORMAT, refused: true };
+ // The throw stays: it is how a module stops here, before the editor below
+ // is built over this message, and a throw after a published refusal still
+ // counts as started. A FIXED message: whatever reports this error may not treat it as text, and
// the detail (which quotes the file) is already on screen above.
throw new Error(`bento/type: the document could not be read (${parsed.err})`);
}