From bde7c576e3e5e7c8899e3ee8311e38bd932e8220 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Fri, 30 Jul 2021 21:36:37 -0500 Subject: [PATCH] Don't crash while listing migrations --- public/js/editorpreviews.js | 33 --------------------------------- public/style.css | 31 ++++++++++--------------------- src/migration/migration.go | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 56 deletions(-) delete mode 100644 public/js/editorpreviews.js diff --git a/public/js/editorpreviews.js b/public/js/editorpreviews.js deleted file mode 100644 index 6f51f81..0000000 --- a/public/js/editorpreviews.js +++ /dev/null @@ -1,33 +0,0 @@ -importScripts('../go_wasm_exec.js'); - -/* -NOTE(ben): The structure here is a little funny but allows for some debouncing. Any postMessages -that got queued up can run all at once, then it can process the latest one. - */ - -let ready = false; -let inputData = null; - -onmessage = ({ data }) => { - inputData = data; - setTimeout(doPreview, 0); -} - -const go = new Go(); -WebAssembly.instantiateStreaming(fetch('../parsing.wasm'), go.importObject) - .then(result => { - go.run(result.instance); // don't await this; we want it to be continuously running - ready = true; - setTimeout(doPreview, 0); - }); - -const doPreview = () => { - if (!ready || inputData === null) { - return; - } - - const result = parseMarkdown(inputData); - inputData = null; - - postMessage(result); -} diff --git a/public/style.css b/public/style.css index 41b17fa..3bcc7d1 100644 --- a/public/style.css +++ b/public/style.css @@ -7289,6 +7289,9 @@ hr { border-top-style: solid; max-width: 300px; } +.mono { + font-family: "Fira Mono", monospace; } + article code { font-family: "Fira Mono", monospace; } @@ -7443,6 +7446,9 @@ article code { .minh-5 { min-height: 16rem; } +.minh-6 { + min-height: 32rem; } + .fira { font-family: "Fira Sans", sans-serif; } @@ -8004,27 +8010,10 @@ pre { border: 0px solid transparent; /* Not themed */ } -.editor .toolbar { - width: 95%; - margin: 10px auto; } - .editor .toolbar select { - font-size: 10pt; - border: 0px; } - .editor .toolbar select:hover { - border: 0px; } - .editor .toolbar select:focus { - border: 0px; } - .editor .toolbar #bold { - font-weight: bold; } - .editor .toolbar #italic { - font-style: italic; } - .editor .toolbar #underline { - text-decoration: underline; } - .editor .toolbar #monospace { - font-family: monospace; } - .editor .toolbar #url { - text-decoration: underline; - font-style: italic; } +@media screen and (min-width: 30em) { + #preview-container { + max-height: calc(100vh - 20rem); + overflow: auto; } } .edit-form .error { margin-left: 5em; diff --git a/src/migration/migration.go b/src/migration/migration.go index 84a46ec..82a1410 100644 --- a/src/migration/migration.go +++ b/src/migration/migration.go @@ -115,13 +115,23 @@ func getCurrentVersion(ctx context.Context, conn *pgx.Conn) (types.MigrationVers return types.MigrationVersion(currentVersion), nil } -func ListMigrations() { - ctx := context.Background() +func tryGetCurrentVersion(ctx context.Context) types.MigrationVersion { + defer func() { + recover() + }() conn := db.NewConn() defer conn.Close(ctx) currentVersion, _ := getCurrentVersion(ctx, conn) + + return currentVersion +} + +func ListMigrations() { + ctx := context.Background() + + currentVersion := tryGetCurrentVersion(ctx) for _, version := range getSortedMigrationVersions() { migration := migrations.All[version] indicator := " "