Fix Joplin sync by upgrading CLI and detecting sync errors

This commit is contained in:
2026-10-02 18:10:15 +09:00
parent f39a7b5a09
commit f5186e57b5
3 changed files with 35 additions and 3 deletions
+27 -2
View File
@@ -7,6 +7,31 @@ RESULT_JSON="/app/data/last_result.json"
log() { printf '%s %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*"; }
fail() { log "ERROR: $*"; exit 1; }
joplin_sync() {
local tmp
local status
tmp="$(mktemp)"
set +e
joplin --profile "$PROFILE" sync 2>&1 | tee "$tmp"
status=${PIPESTATUS[0]}
set -e
if [[ "$status" -ne 0 ]]; then
rm -f "$tmp"
fail "Joplin sync failed with exit code $status"
fi
if grep -Eqi 'Last error:|(^|[[:space:]])Error:' "$tmp"; then
log "ERROR: Joplin reported a sync error:"
grep -Ei 'Last error:|(^|[[:space:]])Error:' "$tmp" || true
rm -f "$tmp"
exit 1
fi
rm -f "$tmp"
}
: "${JOPLIN_WEBDAV_URL:?JOPLIN_WEBDAV_URL is required}"
: "${JOPLIN_WEBDAV_USERNAME:?JOPLIN_WEBDAV_USERNAME is required}"
@@ -33,7 +58,7 @@ fi
# Pull the current remote state first. This is important when PC/mobile also use the same WebDAV target.
log "Synchronising Joplin from WebDAV before writing..."
joplin --profile "$PROFILE" sync
joplin_sync
if [[ "${JOPLIN_WRITE_ENABLED,,}" != "true" ]]; then
log "JOPLIN_WRITE_ENABLED=false: sync-only safety mode. No paper note will be written."
@@ -86,6 +111,6 @@ log "Importing report into Joplin notebook: $JOPLIN_NOTEBOOK"
joplin --profile "$PROFILE" import "$TMP_MD" "$JOPLIN_NOTEBOOK" --format md -f
log "Synchronising Joplin changes to WebDAV..."
joplin --profile "$PROFILE" sync
joplin_sync
log "Completed: $REPORT_TITLE ($REPORT_COUNT papers)"