Add comprehensive logging to handleImageUpload + fix saveField re-throw
Logging added at every step: - handleImageUpload entry - dimPromise resolution - thumbPromise resolution - Upload response status + ok flag + url - r.json() resolution - selectMediaItem call Also: saveField now re-throws after logging so callers know save failed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -731,6 +731,7 @@ export function renderToolbar(config: ToolbarConfig): string {
|
|||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
setSaveState("error");
|
setSaveState("error");
|
||||||
console.error("Save failed:", err);
|
console.error("Save failed:", err);
|
||||||
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1149,6 +1150,7 @@ export function renderToolbar(config: ToolbarConfig): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleImageUpload(file, popover, annotation, element, imgEl) {
|
function handleImageUpload(file, popover, annotation, element, imgEl) {
|
||||||
|
console.log("[emdash] handleImageUpload called, file:", file.name);
|
||||||
var collection = annotation.collection;
|
var collection = annotation.collection;
|
||||||
var id = annotation.id;
|
var id = annotation.id;
|
||||||
var field = annotation.field;
|
var field = annotation.field;
|
||||||
@@ -1180,6 +1182,7 @@ export function renderToolbar(config: ToolbarConfig): string {
|
|||||||
});
|
});
|
||||||
|
|
||||||
dimPromise.then(function(dims) {
|
dimPromise.then(function(dims) {
|
||||||
|
console.log("[emdash] dims resolved:", JSON.stringify(dims));
|
||||||
// Generate a thumbnail for large images to avoid OOM in server-side
|
// Generate a thumbnail for large images to avoid OOM in server-side
|
||||||
// blurhash generation on memory-constrained runtimes (Workers).
|
// blurhash generation on memory-constrained runtimes (Workers).
|
||||||
// Thumbnail fits within a 64x64 box (scale by max dimension) so that
|
// Thumbnail fits within a 64x64 box (scale by max dimension) so that
|
||||||
@@ -1227,6 +1230,7 @@ export function renderToolbar(config: ToolbarConfig): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return thumbPromise.then(function(thumbnail) {
|
return thumbPromise.then(function(thumbnail) {
|
||||||
|
console.log("[emdash] thumbPromise resolved, thumbnail:", thumbnail ? "yes" : "no");
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
if (dims.width) formData.append("width", String(dims.width));
|
if (dims.width) formData.append("width", String(dims.width));
|
||||||
@@ -1241,8 +1245,7 @@ export function renderToolbar(config: ToolbarConfig): string {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(function(r) {
|
.then(function(r) {
|
||||||
console.log("[emdash] Upload response status:", r.status);
|
console.log("[emdash] Upload response status:", r.status, "ok:", r.ok, "url:", r.url);
|
||||||
console.log("[emdash] Upload response headers:", r.headers.get("content-type"));
|
|
||||||
if (!r.ok) {
|
if (!r.ok) {
|
||||||
return r.text().then(function(text) {
|
return r.text().then(function(text) {
|
||||||
console.log("[emdash] Upload error text:", text);
|
console.log("[emdash] Upload error text:", text);
|
||||||
@@ -1257,9 +1260,12 @@ export function renderToolbar(config: ToolbarConfig): string {
|
|||||||
return r.json();
|
return r.json();
|
||||||
})
|
})
|
||||||
.then(function(data) {
|
.then(function(data) {
|
||||||
|
console.log("[emdash] r.json() resolved, data:", JSON.stringify(data));
|
||||||
if (!data.data || !data.data.item) throw new Error("Upload failed: no item returned");
|
if (!data.data || !data.data.item) throw new Error("Upload failed: no item returned");
|
||||||
var item = data.data.item;
|
var item = data.data.item;
|
||||||
selectMediaItem(item, annotation, element, imgEl);
|
console.log("[emdash] Calling selectMediaItem with item id:", item.id);
|
||||||
|
// Return the saveField promise so rejections propagate to catch
|
||||||
|
return selectMediaItem(item, annotation, element, imgEl);
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
console.error("Upload error:", err);
|
console.error("Upload error:", err);
|
||||||
|
|||||||
Reference in New Issue
Block a user