mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-28 14:51:06 -04:00
fix(server): reject duplicate nest ids, invalid metadata and bare --database
- POST /api/nests with an existing id (active or deleted) now returns 409 with the current record instead of a 500 from the UNIQUE constraint. - Uploaded nest metadata must have string text fields and a defined status; null fields and undefined statuses (e.g. 99) are 400 instead of a 500 or a stored invalid value. - --database <path> is accepted alongside --database=<path>; a missing or repeated path fails startup instead of silently using OPENNEST_DB/default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a7073d38c
commit
5dff83cfb8
7 files changed
+309
-37
No files matched your search
@@ -142,6 +142,9 @@ public sealed partial class NestDatabase : IDisposable
|
||||
lock (_sync)
|
||||
{
|
||||
using var transaction = _connection.BeginTransaction();
|
||||
// Ids are client-allocated: an existing id, active or deleted, is a conflict, not a replacement.
|
||||
if ((Get(id) ?? Get(id, deleted: true)) is { } existing)
|
||||
throw new RevisionConflictException(existing, "A nest with this id already exists.");
|
||||
using var command = _connection.CreateCommand();
|
||||
command.Transaction = transaction;
|
||||
command.CommandText = """
|
||||
@@ -488,7 +491,8 @@ public sealed partial class NestDatabase : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class RevisionConflictException(NestRecord current) : Exception("The nest has changed. Reload or Save As.")
|
||||
public sealed class RevisionConflictException(NestRecord current, string message = "The nest has changed. Reload or Save As.")
|
||||
: Exception(message)
|
||||
{
|
||||
public NestRecord Current { get; } = current;
|
||||
}
|
||||
Reference in new issue
Block a user