ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Otared Kavian <otared@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: [NTG-context] Re: Where is th efile status.html ?
Date: Sun, 21 Sep 2025 00:49:48 +0200	[thread overview]
Message-ID: <1A1F3EC1-A9E1-485E-86C0-3B31BDBE6FF3@gmail.com> (raw)
In-Reply-To: <e42f8f3e-4d90-4efa-878a-174d920e3f9d@xs4all.nl>


[-- Attachment #1.1: Type: text/plain, Size: 1989 bytes --]

Hi Hans,

Thanks for your reply. Indeed the file status.html is very useful to find easily errors, and I rely on it heavily… The reason for which I did not notice its disappearance is that I was still using version 2025.01.04…

I did uncomment lines 322–399 in trac-deb.lmt, but the file « jobname ».status.html does not appear when there is an error in my inputfile.

I am sending the modified trac-deb.lmt in case it may be helpful.

Best regards: Otared



> On 20 Sep 2025, at 14:54, Hans Hagen via ntg-context <ntg-context@ntg.nl> wrote:
> 
> On 9/20/2025 1:40 PM, Otared Kavian wrote:
>> Hi Hans,
>> Thanks for the new update from 2025-09-19 which I just downloaded.
>> I notice that now ConTeXt does not produce anymore the file « jobname ».status.html which was very useful to pin down errors. Am I missing something, or is there a new way to have this nice feature working again ?
> 
> hm, so it was used ... you can uncomment line 322-399 in trac-deb.lmt and tell me if it works
> 
> Hans
> 
> -----------------------------------------------------------------
>                                          Hans Hagen | PRAGMA ADE
>              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -----------------------------------------------------------------
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
> webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
> archive  : https://github.com/contextgarden/context
> wiki     : https://wiki.contextgarden.net
> ___________________________________________________________________________________

Otared Kavian
e-mail: otared@gmail.com
Phone: +33 6 88 26 70 95





[-- Attachment #1.2.1: Type: text/html, Size: 924 bytes --]

[-- Attachment #1.2.2: trac-deb.lmt --]
[-- Type: application/octet-stream, Size: 17024 bytes --]

if not modules then modules = { } end modules ['trac-deb'] = {
    version   = 1.001,
    comment   = "companion to trac-deb.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- This is an old mechanism, a result of some experiments in the early days of
-- luatex and mkiv, but still nice anyway. I will clean it up in lmtx.

local status = status

local tonumber, tostring, type = tonumber, tostring, type
local format, concat, match, find, gsub = string.format, table.concat, string.match, string.find, string.gsub

local report_nl    = logs.newline
local report_str   = logs.writer

tracers            = tracers or { }
local tracers      = tracers

local implement    = interfaces.implement

local ioflush      = io.flush
local ioread       = io.read
local ossleep      = os.sleep
local osexit       = os.exit
local writenl      = texio.writenl
local write        = texio.write

local runlocal     = tex.runlocal
local terminaldata = false
local context      = context

implement {
    name    = "fetchterminaldata",
    actions = function()
        context(terminaldata)
    end,
}

function texio.terminal()
    writenl("\n" .. "entering interactive mode, use \\quit to abort reading" .."\n\n")
    while true do
        write(">")
        ioflush()
        terminaldata = ioread()
        if terminaldata == "\\quit" then
            terminaldata = false
            break
        else
            runlocal("t_syst_terminal_data",nil,nil,true) -- obeymode
        end
    end
end

implement {
    name      = "readfromterminal",
    public    = true,
    protected = true,
    actions   = texio.terminal,
}

local savedluaerror = nil
local usescitelexer = nil
local quitonerror   = true

local function errorreporter(luaerror)
    local category = luaerror and "lua error" or "tex error"
    local report = logs.reporter(category)
    logs.enable(category)
    return report
end

function tracers.showlines(filename,linenumber,offset,luaerrorline)
    local data = io.loaddata(filename)
    if not data or data == "" then
        local hash = url.hashed(filename)
        if not hash.noscheme then
            local ok, d, n = resolvers.loaders.byscheme(hash.scheme,filename)
            if ok and n > 0 then
                data = d
            end
        end
    end
    local scite = usescitelexer and require("util-sci")
    if scite then
        return utilities.scite.tohtml(data,"tex",linenumber or true,false)
    else
        local lines = data and string.splitlines(data)
        if lines and #lines > 0 then
            if luaerrorline and luaerrorline > 0 then
                -- lua error: linenumber points to last line
                local start = "\\startluacode"
                local stop  = "\\stopluacode"
                local n = linenumber
                for i=n,1,-1 do
                    local line = lines[i]
                    if not line then
                        break
                    elseif find(line,start) then
                        n = i + luaerrorline - 1
                        if n <= linenumber then
                            linenumber = n
                        end
                        break
                    end
                end
            end
            offset = tonumber(offset) or 10
            linenumber = tonumber(linenumber) or 10
            local start = math.max(linenumber - offset,1)
            local stop = math.min(linenumber + offset,#lines)
            if stop > #lines then
                return "<linenumber past end of file>"
            else
                local result, fmt = { }, "%" .. #tostring(stop) .. "d %s  %s"
                for n=start,stop do
                    result[#result+1] = format(fmt,n,n == linenumber and ">>" or "  ",lines[n])
                end
                return concat(result,"\n")
            end
        else
            return "<empty file>"
        end
    end
end

-- todo: last tex error has ! prepended
-- todo: some nested errors have two line numbers
-- todo: collect errorcontext in string (after code cleanup)
-- todo: have a separate status.lualinenumber
-- todo: \starttext bla \blank[foo] bla \stoptext

local nop           = function() end
local resetmessages = status.resetmessages or nop
local erroroffset   = 10

local function processerror(errortype)
    local readstate      = status.getreadstate()
    local filename       = readstate.filename
    local linenumber     = readstate.linenumber
    local skiplinenumber = readstate.skiplinenumber
    local errorstate     = status.errorstate
    local lastcontext    = errorstate.errorcontext
    local lasttexerror   = errorstate.error or "?"
    local lastluaerror   = errorstate.luaerror or "?" -- lasttexerror
    local luaerrorline   = match(lastluaerror,[[lua%]?:.-(%d+)]]) or (lastluaerror and find(lastluaerror,"?:0:",1,true) and 0)
    local lastmpserror   = match(lasttexerror,[[^.-mp%serror:%s*(.*)$]])
    resetmessages()
    lastluaerror = gsub(lastluaerror,"%[\\directlua%]","[ctxlua]")
    local specification = {
        filename       = filename,
        linenumber     = linenumber,
        skiplinenumber = skiplinenumber,
        offset         = erroroffset,
        contexterror   = job.contexterror,
        lasttexerror   = lasttexerror,
        lastmpserror   = lastmpserror,
        lastluaerror   = lastluaerror, -- can be the same as lasttexerror
        luaerrorline   = luaerrorline,
        lastcontext    = lastcontext,
        lasttexhelp    = tex.gethelptext(),
        errortype      = errortype,
    }
    job.errorstate = specification
    tracers.printerror(specification)
    if job and type(job.disablesave) == "function" then
        job.disablesave()
    end
    lua.setexitcode(1)
end

directives.register("system.quitonerror",  function(v) quitonerror   = toboolean(v) end)
directives.register("system.usescitelexer",function(v) usescitelexer = toboolean(v) end)

local busy = false

function tracers.printerror(specification)
    if not busy then
        busy = true
        local errorvalues  = table.swapped(tex.geterrorvalues())
        local filename     = specification.filename
        local linenumber   = specification.linenumber
        local lasttexerror = specification.lasttexerror
        local lastmpserror = specification.lastmpserror
        local lastluaerror = specification.lastluaerror
        local lastcontext  = specification.lastcontext
        local luaerrorline = specification.luaerrorline
        local errortype    = specification.errortype
        local offset       = specification.offset or erroroffset
        local endoffile    = specification.endoffile
        local report       = errorreporter(luaerrorline)
        if errortype == errorvalues.warning then
            report("warning error: %s",lasttexerror or "-")
            busy = false;
            return;
        elseif errortype == errorvalues.eof then
            report("runaway error: %s",lasttexerror or "-")
            if not quitonerror and texio.terminal then
                texio.terminal() -- not well tested
            end
        elseif errortype == errorvalues.condition then
            linenumber = specification.skiplinenumber
            if linenumber > 0 then
                report("condition error on line %s in file %s: %s",linenumber,filename,lasttexerror)
                report_nl()
                report_str(tracers.showlines(filename,linenumber,offset,tonumber(luaerrorline)))
                report_nl()
            else
                report("runaway condition error: %s",lasttexerror or "-")
            end
            quitonerror = true
        elseif not filename then
            report("fuzzy error:")
            report("  tex: %s",lasttexerror or "-")
            report("  lua: %s",lastluaerror or "-")
            report("  mps: %s",lastmpserror or "-")
        elseif type(filename) == "number" then
            report("error on line %s of filehandle %s: %s ...",linenumber,lasttexerror)
        else
            report_nl()
            if luaerrorline then
                if linenumber == 0 or not filename or filename == "" then
                    print("\nfatal lua error:\n\n",lastluaerror,"\n")
                    luatex.abort()
                    return
                else
                    report("lua error on line %s in file %s:\n\n%s",linenumber,filename,lastluaerror)
                end
            elseif lastmpserror then
                report("mp error on line %s in file %s:\n\n%s",linenumber,filename,lastmpserror)
            else
                report("tex error on line %s in file %s: %s",linenumber,filename,lasttexerror)
                if lastcontext then
                    report_nl()
                    report_str(lastcontext)
                    report_nl()
                else
                    report_nl()
                 -- tex.showcontext()
                end
                if lastluaerror and not match(lastluaerror,"^%s*[%?]*%s*$") then
                    print("\nlua error:\n\n",lastluaerror,"\n")
                    quitonerror = true
                end
            end
            report_nl()
            report_str(tracers.showlines(filename,linenumber,offset,tonumber(luaerrorline)))
            report_nl()
        end
        if quitonerror then
            local name = tex.jobname or ""
            if name ~= "" then
                table.save(name .. "-error.log",specification)
            end
            local help = specification.lasttexhelp
            if help and #help > 0 then
                -- If we get rubish a NULL is forgotten in engine error trigger!
                report_nl()
                report_str(help)
                report_nl()
                report_nl()
            end
            luatex.abort()
        end
        busy = false
    end
end

luatex.wrapup(function() os.remove(tex.jobname .. "-error.log") end)

local function processwarning()
    local warningstate = status.warningstate
    local lastwarning  = warningstate.warning or "?"
    local lastlocation = warningstate.warningtag or "?"
    resetmessages()
    tracers.printwarning {
        lastwarning  = lastwarning,
        lastlocation = lastlocation,
    }
end

function tracers.printwarning(specification)
    logs.report("luatex warning","%s: %s",specification.lastlocation,specification.lastwarning)
end

directives.register("system.errorcontext", function(v)
    erroroffset = tonumber(v) or erroroffset -- is set in the configuration file
end)

callbacks.register {
    name     = "show_error_message",
    frozen   = true,
    disabled = true,
}

callbacks.register {
    name   = "show_warning_message",
    frozen = true,
    action = processwarning,
}

callbacks.register {
    name   = "intercept_lua_error",
    frozen = true,
    action = processerror
}

callbacks.register {
    name   = "intercept_tex_error",
    frozen = true,
    action = function(mode,errortype)
        processerror(errortype)
        return mode
    end
}

-- tracers.processerror = processerror

-- Let's no longer do this in lmtx .. it was actually a proof of concept. There is no
-- reliable way to pop up a browser anyway. We keep the code around becuae if really
-- needed we can plug it into the normal error handler as addendum.

lmx = lmx or { }

lmx.htmfile = function(name) return environment.jobname .. "-status.html" end
lmx.lmxfile = function(name) return resolvers.findfile(name,'tex') end

local function reportback(lmxname,default,variables)
    if lmxname == false then
        return variables
    else
        local name = lmx.show(type(lmxname) == "string" and lmxname or default,variables)
        if name then
            logs.report("context report","file: %s",name)
        end
    end
end

local function showerror(lmxname)
    local readstate    = status.getreadstate()
    local filename     = readstate.filename
    local linenumber   = tonumber(readstate.linenumber) or 0
    local errorcontext = ""
    if not filename then
         filename     = status.iocodes[readstate.iocode]
        errorcontext = 'error in filename'
     else
         errorcontext = tracers.showlines(filename,linenumber,offset)
     end
     local variables = {
        ['title']                = 'ConTeXt Error Information',
         ['errormessage']         = status.geterrorstate().error or "?",
         ['linenumber']           = linenumber,
         ['color-background-one'] = lmx.get('color-background-yellow'),
         ['color-background-two'] = lmx.get('color-background-purple'),
         ['filename']             = filename,
         ['errorcontext']         = errorcontext,
    }
    reportback(lmxname,"context-error.lmx",variables)
    luatex.abort()
end

lmx.showerror = showerror

function lmx.overloaderror(v)
    if v == "scite" then
        usescitelexer = true
    end
    callbacks.register { name = "show_error_message",  action = function() showerror() end }
    callbacks.register { name = "intercept_lua_error", action = function() showerror() end }
    callbacks.register { name = "intercept_tex_error", action = function() showerror() end }
end

directives.register("system.showerror", lmx.overloaderror)

-- This is also gone

local debugger = utilities.debugger

local function trace_calls(n)
     debugger.enable()
     luatex.registerstopactions(function()
         debugger.disable()
         debugger.savestats(tex.jobname .. "-luacalls.log",tonumber(n))
    end)
    trace_calls = function() end
end

directives.register("system.tracecalls", function(n)
   trace_calls(n)
end) -- indirect is needed for nilling

-- Again something that has become obsolete because it is not that usefull as normally one
-- runs from an editor and when run unattended it makes no sense either.

local editor = [[scite "-open:%filename%" -goto:%linenumber%]]
--
-- directives.register("system.editor",function(v)
--     editor = v
-- end)
--
-- local function call_edit_callback(filename,linenumber)
--     if editor then
--         editor = gsub(editor,"%%s",filename)
--         editor = gsub(editor,"%%d",linenumber)
--         editor = gsub(editor,"%%filename%%",filename)
--         editor = gsub(editor,"%%linenumber%%",linenumber)
--         logs.report("system","starting editor: %s",editor)
--         os.execute(editor)
--     end
-- end
--
-- callback.register("call_edit",call_edit_callback)

implement { name = "showtrackers",       public = true, protected = true, actions = trackers.show }
implement { name = "enabletrackers",     public = true, protected = true, actions = trackers.enable,     arguments = "optional" }
implement { name = "disabletrackers",    public = true, protected = true, actions = trackers.disable,    arguments = "optional" }
implement { name = "resettrackers",      public = true, protected = true, actions = trackers.reset }

implement { name = "showdirectives",     public = true, protected = true, actions = directives.show }
implement { name = "enabledirectives",   public = true, protected = true, actions = directives.enable,   arguments = "optional" }
implement { name = "disabledirectives",  public = true, protected = true, actions = directives.disable,  arguments = "optional" }

implement { name = "showexperiments",    public = true, protected = true, actions = experiments.show }
implement { name = "enableexperiments",  public = true, protected = true, actions = experiments.enable,  arguments = "optional" }
implement { name = "disableexperiments", public = true, protected = true, actions = experiments.disable, arguments = "optional" }

--------- { name = "overloaderror",      public = true, protected = true, actions = lmx.overloaderror }
implement { name = "showlogcategories",  public = true, protected = true, actions = logs.show }

local debugger = utilities.debugger

local profiling = false

directives.register("system.profile",function(n)
    if not profiling then
        n = tonumber(n) or 0
        luatex.registerstopactions(function()
            debugger.disable()
            debugger.savestats("luametatex-profile.log",n)
            report_nl()
            logs.report("system","profiler stopped, threshold %i, log saved in %a",n,"luametatex-profile.log")
            report_nl()
        end)
        logs.report("system","profiler started")
        debugger.enable()
        profiling = true
    end
end)

local report = logs.reporter("[[diagnostic]]")

implement {
    name      = "diagnostic",
    public    = true,
 -- protected = false, -- expandable
    arguments = { "optional", "string" },
    actions   = function(t,s)
        if t == "quit" then
            report(s)
            osexit()
        else
            t = tonumber(t)
            if t then
                report("%s (sleep: %.3N)",s,t)
                ioflush()
                ossleep(t)
            else
                report(s)
                ioflush()
            end
        end
    end
}

[-- Attachment #1.2.3: Type: text/html, Size: 3546 bytes --]

[-- Attachment #2: Type: text/plain, Size: 511 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2025-09-20 22:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-20 11:40 [NTG-context] " Otared Kavian
2025-09-20 12:54 ` [NTG-context] " Hans Hagen via ntg-context
2025-09-20 22:49   ` Otared Kavian [this message]
2025-09-21 17:25     ` Hans Hagen via ntg-context

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1A1F3EC1-A9E1-485E-86C0-3B31BDBE6FF3@gmail.com \
    --to=otared@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).