Skip to content

Commit 28d2421

Browse files
committed
fix: improve resolver error propagation, sanitization, and consistency
1 parent 20a83c7 commit 28d2421

6 files changed

Lines changed: 28 additions & 15 deletions

File tree

tests/test_downloads_tab_workflow_route.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'node:fs';
22
import path from 'node:path';
33
import test from 'node:test';
44
import assert from 'node:assert/strict';
5+
import { normalizePathIdentity } from '../web/resolver/utils/html_utils.js';
56

67
const projectRoot = path.resolve(import.meta.dirname, '..');
78
const queueMethodsSource = fs.readFileSync(

web/resolver/actions/queue_methods.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ export const queueMethods = {
495495
if (typeof document === 'undefined') return null;
496496

497497
for (const selector of this.getWorkflowTabActiveSelectors()) {
498-
let elements = [];
498+
let elements;
499499
try {
500500
elements = Array.from(document.querySelectorAll(selector));
501501
} catch (error) {
@@ -900,7 +900,7 @@ export const queueMethods = {
900900
let bestMatch = null;
901901

902902
for (const selector of this.getWorkflowTabSearchSelectors()) {
903-
let elements = [];
903+
let elements;
904904
try {
905905
elements = Array.from(document.querySelectorAll(selector));
906906
} catch (error) {

web/resolver/actions/resolve_download_methods.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ export const resolveDownloadMethods = {
335335
const batchWorkflowKey = this.getWorkflowScopedQueueKey();
336336
let completed = 0;
337337
let failed = 0;
338+
let cancelled;
339+
let batchError;
340+
let hasBatchError = false;
338341
try {
339342
for (const missing of targets) {
340343
if (this.batchSearchCancelRequested) {
@@ -351,20 +354,25 @@ export const resolveDownloadMethods = {
351354
completed += 1;
352355
this.updateBatchFooterButtons();
353356
}
357+
} catch (error) {
358+
batchError = error;
359+
hasBatchError = true;
354360
} finally {
355-
const cancelled = this.batchSearchCancelRequested;
361+
cancelled = this.batchSearchCancelRequested;
356362
this.batchSearchRunning = false;
357363
this.batchSearchCancelRequested = false;
358364
this.persistSearchStateForActiveWorkflow();
359365
this.updateBatchFooterButtons();
360-
const suffix = failed ? `, ${failed} failed` : '';
361-
if (cancelled) {
362-
this.showNotification(`Stopped search after ${completed} of ${targets.length} model${targets.length === 1 ? '' : 's'}${suffix}.`, 'info');
363-
return;
364-
}
365366
}
366367

367368
const suffix = failed ? `, ${failed} failed` : '';
369+
if (cancelled) {
370+
this.showNotification(`Stopped search after ${completed} of ${targets.length} model${targets.length === 1 ? '' : 's'}${suffix}.`, 'info');
371+
return;
372+
}
373+
if (hasBatchError) {
374+
throw batchError;
375+
}
368376
this.showNotification(`Finished search for ${completed} model${completed === 1 ? '' : 's'}${suffix}.`, failed ? 'error' : 'success');
369377
},
370378

@@ -2904,15 +2912,15 @@ export const resolveDownloadMethods = {
29042912
const url = btn.dataset.url;
29052913
const filename = btn.dataset.filename;
29062914
const category = btn.dataset.category;
2907-
let pathMetadata = null;
2915+
let pathMetadata;
29082916
try {
29092917
pathMetadata = btn.dataset.pathMetadata
29102918
? JSON.parse(decodeURIComponent(btn.dataset.pathMetadata))
29112919
: null;
29122920
} catch (_error) {
29132921
pathMetadata = null;
29142922
}
2915-
let downloadMetadata = null;
2923+
let downloadMetadata;
29162924
try {
29172925
downloadMetadata = btn.dataset.downloadMetadata
29182926
? JSON.parse(decodeURIComponent(btn.dataset.downloadMetadata))

web/resolver/model_resolver.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ export class ModelResolver {
885885
const currentWorkflow = workflow || app?.graph?.serialize?.();
886886
if (!currentWorkflow) return;
887887

888-
let signature = '';
888+
let signature;
889889
try {
890890
signature = JSON.stringify((currentWorkflow.nodes || []).map((node) => [
891891
node?.id,
@@ -1017,7 +1017,7 @@ export class ModelResolver {
10171017
for (const el of allElements) {
10181018
if (el.textContent?.includes('following models were not found') &&
10191019
el.children.length === 0) {
1020-
el.parentElement?.insertBefore(btnContainer, el.nextSibling);
1020+
el.parentElement?.insertBefore(autoResolveBtn, el.nextSibling);
10211021
break;
10221022
}
10231023
}
@@ -1082,7 +1082,7 @@ export class ModelResolver {
10821082
);
10831083

10841084
let node;
1085-
while (node = walker.nextNode()) {
1085+
while ((node = walker.nextNode())) {
10861086
if (node.textContent?.toLowerCase().includes(filename)) {
10871087
// Found text containing filename - now find parent with Download button
10881088
let parent = node.parentElement;

web/resolver/search/download_target_methods.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { getSvgIcon } from "../../utils/icon_utils.js";
55
import { createFloatingTreePicker } from "../utils/tree_picker.js";
66
import { safeStorage } from "../utils/html_utils.js";
77
const localStorage = safeStorage;
8+
const invalidWindowsPathCharacters = new RegExp(
9+
`[<>:"|?*${Array.from({ length: 32 }, (_, code) => String.fromCharCode(code)).join('')}]+`,
10+
'g'
11+
);
812
export const downloadTargetMethods = {
913
/**
1014
* Ensure all models are loaded for the dropdown.
@@ -1198,7 +1202,7 @@ export const downloadTargetMethods = {
11981202
let text = String(value || '').trim() || fallback;
11991203
text = text
12001204
.replace(/[\\/]+/g, '_')
1201-
.replace(/[<>:"|?*\x00-\x1f]+/g, '_')
1205+
.replace(invalidWindowsPathCharacters, '_')
12021206
.replace(/\s+/g, ' ')
12031207
.replace(/^[\s.]+|[\s.]+$/g, '');
12041208
if (!text || text === '.' || text === '..') {

web/resolver/shell/workflow_state_methods.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ export const workflowStateMethods = {
453453
},
454454

455455
cloneSearchState(state = {}, { preserveActive = false } = {}) {
456-
let clone = {};
456+
let clone;
457457
try {
458458
clone = JSON.parse(JSON.stringify(state || {}));
459459
} catch (error) {

0 commit comments

Comments
 (0)