CONFIG issues in v2

I’ve tried to re-implement my old v1 Toolbar using v2 config.set in space-lua with no luck (I only get the default toolbar with the action buttons that ship by default). When I check the browser console I see this error:

Error evaluating script: Config key not defined: plugs at [[Library/Std/Config@493]]

When I go to /Library/Std/Config, I see what looks like a function definition for config.set?

My current CONFIG is two space-lua blocks:

  1. copied from the silverbullet.md version (I’ll configure it further once I get even this to work)
  2. the implementation block from Library/Std/Page Templates

Any ideas?

As far as I remember, the run calls were changed in the past (but maybe, I’m outdated, too :slight_smile) from “editor.invokeCommand” to “system.invokeCommand” and the others tooo from editor to system.

This is my actionbar, as it is working with v2 from a few days ago:

config.set {
  actionButtons = {
    {
      icon = "home",
      run = function()
        system.invokeCommand("Navigate: Home")
      end,
      description = "Go to the index page"
    },
    {
      icon = "book",
      run = function()
        system.invokeCommand("Navigate: Page Picker")
      end,
      description = "Open page"
    },
    {
      icon = "plus-circle",
      run = function()
        system.invokeCommand("Page: Create Subpage")
      end,
      description = "Create Subpage"
    },
    {
      icon = "calendar",
      run = function()
        system.invokeCommand("Navigate: Todays Journal")
      end,
      description = "Open or create todays journal Note"
    },
    {
      icon = "search",
      run = function()
        -- system.invokeCommand("Search Space")
        system.invokeCommand("Silversearch: Search")
      end,
      description = "Search Space with Silversearch"
    },    
    {
      icon = "trash",
      run = function()
        system.invokeCommand("Page: Delete")
      end,
      description = "Delete Page"
    },
    {
      icon = "arrow-left",
      run = function()
        system.invokeCommand("Navigate: Back in History")
      end,
      description = "Go to the previous page"
    },   
 }
}

Hope, that helps.

What I do not understand in your code: How does the templates page is related to the problem?
As far as I understand, you do not need to include the "implementation" block in your config, as the very part in this template page, is the code, which silverbullet is actially using.

On the other hand, the error message seems to direct to the "pugs = ..." line.

Maybe you could paste your whole config here to double check in general...

(Please anyone correct me, If I'm wrong!)

I was confused myself but without the second block (see below), my space doesn’t recognize the template command names nor do the templates show up in the list under “Page: From Template”

Here is my total CONFIG file:

config.set {
  plugs = {
    "github:joekrill/silverbullet-treeview/treeview.plug.js"
  },
  actionButtons = {
    {
      icon = "home",
      description = "Go to the index page",
      run = function()
        editor.invokeCommand("Navigate: Home")
      end
    },
    {
      icon = "activity",
      description = "What's new",
      run = function()
        editor.navigate {
          page = "CHANGELOG"
        }
      end
    },
    {
      icon = "message-circle",
      description = "Community",
      run = function()
        editor.openUrl "https://community.silverbullet.md"
      end
    },
    {
      icon = "book",
      description = "Open page",
      run = function()
        editor.invokeCommand("Navigate: Page Picker")
      end
    },
    {
      icon = "terminal",
      description = "Run command",
      run = function()
        editor.invokeCommand "Open Command Palette"
      end,
    }
  },
  smartQuotes = {
    enabled = true,
  },
  queryCollate = {
    enabled = true,
    locale = "en",
    options = {
      caseFirst = "upper"
    }
  }
}
-- priority: 10
local function createPageFromTemplate(templatePage, pageName)
  -- Won't override an existing page
  if space.pageExists(pageName) then
    editor.flashNotification("Page " .. pageName .. " already exists", "error")
    return
  end
  local tpl, fm = template.fromPage(templatePage)
  local initialText = ""
  if fm.frontmatter then
    initialText = "---\n"
      .. string.trim(template.new(fm.frontmatter)())
      .. "\n---\n"
  end
  -- Write an empty page to start
  space.writePage(pageName, initialText)
  editor.navigate({kind = "page", page = pageName})
  -- Insert there, supporting |^| cursor placeholder
  editor.insertAtPos(tpl(), #initialText, true)
end

-- Create commands for all page templates with a command key in frontmatter
for pt in query[[
    from index.tag "meta/template/page"
    where _.tag == "page" and _.command
    order by _.priority desc
  ]] do
  command.define {
    name = pt.command,
    key = pt.key,
    mac = pt.mac,
    run = function()
      local pageName
      if pt.suggestedName then
        pageName = (template.new(pt.suggestedName))()
      end
      if pt.confirmName != false then
        pageName = editor.prompt("Page name", pageName)
      end
      if not pageName then
        return
      end
      if pt.openIfExists and space.pageExists(pageName) then
        editor.navigate({kind = "page", page = pageName})
        return
      end
      createPageFromTemplate(pt.name, pageName)
    end
  }
  print("Registered", pt.command)
end

command.define {
  name = "Page: From Template",
  run = function()
    local pageTemplates = query[[from index.tag "meta/template/page" where _.tag == "page"]]
    local selected = editor.filterBox("Page template", pageTemplates, "Pick the template you would like to instantiate")
    if not selected then
      return
    end
    local pageName
    if selected.suggestedName then
      pageName = (template.new(selected.suggestedName))()
    end
    pageName = editor.prompt("Page name", pageName)
    if not pageName then
      return
    end
    createPageFromTemplate(selected.name, pageName)
  end
}

Very strange. I suppose, there must be something wrong in your whole space…

Could you please take a look at (er even better: paste here) your page “/Library/Std/Space Overview/” ?

(Note: The page is not existing in your filesystem, but should be shown in your space.)

It shows every codeblock silverbullet has consumed. So e.g. the page “Library/Std/Template” should be there, too.
If not, I would suggest a new installation, as it seems, the standard-libraries are missing somehow.

Mut maybe someone else has some other hints?

/Library/Std/Space Overview:
I get a brief flash of an error before it tries to create it as a new markdown file

Library/Std/Template: this I do have:

#meta

Implements useful template functions

```space-lua
-- priority: 10
-- Template API root table
template = {}
-- Template storage table
templates = {}

-- Iterates over a table/array and applies a function to each element,
-- concatenating the results
function template.each(tbl, fn)
    local result = {}
    for _, item in ipairs(tbl) do
        table.insert(result, fn(item))
    end
    return table.concat(result)
end

-- Creates a new template function from a string template
function template.new(templateStr)
  -- Preprocess: strip indentation
  local lines = {}
  local splitLines = string.split(templateStr, "\n")
  for _, line in ipairs(splitLines) do
    line = string.gsub(line, "^    ", "")
    table.insert(lines, line)
  end
  templateStr = table.concat(lines, "\n")
  return function(obj)
    return spacelua.interpolate(templateStr, obj)
  end
end

-- Creates a template-based slash command, keys for def are:
--   name: name of the slash command
--   description: description of the slash command
--   onlyContexts: parent AST nodes in which this slash command is available, defaults to everywhere
--   exceptContexts: parent AST nodes in which this slash command is not available
--   template: template function to apply
--   insertAt: position to insert the template into
--   match: match string to apply the template to
--   matchRegex: match regex to apply the template to
function template.defineSlashCommand(def)
  slashcommand.define {
    name = def.name,
    description = def.description,
    onlyContexts = def.onlyContexts,
    exceptContexts = def.exceptContexts,
    run = function()
      system.invokeFunction("template.applySnippetTemplate", def.template(), {
        insertAt = def.insertAt,
        match = def.match,
        matchRegex = def.matchRegex
      })
    end
  }
end

OK, there is definitely something wrong.
Could you please describe in short, which version are you using, how did you install (e.g. via docker or binary, or deno, …)? Which OS are you using?

Do you have any plugins defined?
is there anything in your /space/_plugs folder (accessible from OS only, not from Silverbullet), which you did not install yourself? Or removed from silverbullet? You might try to delete everything in there (after backing it up :wink: )

Could you have a look at the developer console of the browser? Are there any errors during startup of silverbullet and/or while opening e.g. the above mentioned page or on “system: reload” via GUI?

Are there any errors in docker or at the commandline during startup or the above?

However, I’m afraid, this gets too deep for me :slight_smile: Don’t have a real clue, what is the issue, but I have a feeling, that you might have:

  • a page with malfunctioning (lua-) code or config anywhere in your space
  • a plugin which is not working correctly
  • a “strange” file or document in your space

which is causing Silverbullets index to fail.

If so, you should see a hint in developer console, I hope…

  • Installed via Docker (on miniPC server running OpenMediaVault) — I actually had to reinstall it recently and copied over many *.md files which may have screwed something up…? :thinking:
  • I don’t have a /space/_plugs folder… :open_mouth:
  • The only error that shows up in the browser console is what I shared before: Error evaluating script: Config key not defined: plugs at [[Library/Std/Config@493]]
  • When I check the docker logs I only see the same error as in the dev console

Is there a way to regenerate the missing files? Or do I just need to do a clean reinstall?

Well, the missing files should not even be there (on the file system), as they are “virtual” anyway. They should “appear” on the fly, only “within” Silverbullet. That’s why you are not able to edit them, too.

I would try to:

  • Delete (or move out of the space) everything under Library/Std - if there is anything in your filesystem. That folder should’nt be there anyway. (However, you might have other folders under Library, that should be fine.
  • Delete your config-file. Maybe there is something wrong with it. And have a look, if there is another config definition in any other file.

To be honest, I’m out if ideas now :slight_smile:

Ah I see — I have nothing in /space/_plugs and nothing in the. I think I’m going to do a fresh install which sucks b/c I’ve had bad luck with re-indexing in the past, but I do think my space is now heavily FUBAR’d…

Ok I feel like an idiot — I had assumed that the latest tag on Docker was going to be v2 but it wasn’t. This explains why I had partial space-lua support but not complete and I think explains almost all of this… :man_facepalming: