I'm trying to arrange and organise things in my KST list of things to do; might be good to mind map it.

kortex debugging

I spent a lot of time this morning fighting kortex; I've started writing the UI, and I needed to start adding some entries to tags. To do that, I use tagcap which basically exec's an editor and copies the resulting text file to a new cell in a tag. All was well and good until I tried adding a second cell to a tag:

[!] UNIQUE constraint failed: cells.metadata

So I started looking through the code and couldn't figure out what was going on. The schema for cells looks like

    id          text unique not null primary key,
    metadata    text unique not null,
    tag         text,
    content     text,
    type        text,
    idx         integer,
    FOREIGN KEY (metadata) REFERENCES metadata(id)

The insert statement for cells is pretty straightforward, too.

        id, metadata, content, type, idx, tag
) VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET metadata=?, content=?, type=?, idx=?

After whacking at this for a bit with some good old fashioned printf debugging, I realised that it was happening while trying to write a cell that existed, i.e. an update. The unique constraint here was the giveaway: for some reason I was trying to create a new cell, not update it. Sure enough, that was the case:

diff --git a/store/cell.go b/store/cell.go
@@ -21,7 +22,7 @@ func NewCell() Cell {

 func GetCell(ctx context.Context, tx *sql.Tx, id string) (Cell, error) {
-       var c Cell
+       var c = Cell{ID: id}
        var meta string

        row := tx.QueryRowContext(ctx,

Simple fix, and now all is right in the world.


The rewrite of nomad is moving along with a good start, with roughly 400 LOC covering the core types, database interactions, configuration, and basic media support. I'm trying to work on blob store, which right now is storing images in Digital Ocean's Space (their S3 alternative). I'm running into ACL problems now: I can't set the default ACL on the bucket (I want this bucket to be public read), and the minio library I'm using doesn't support setting per-object ACLs that I can see. I might try to finangle it or fork the library. I'd rather not bring in the AWS SDK because it's overkill for the very simple use case we have and everyone knows dependencies are liabilities.