Mercurial > prosody-hg
comparison core/configmanager.lua @ 13745:994ea8d54b72 13.0
core.configmanager: Pass name and line number in context
Delays the string interpolation until the warning is logged, which may
slightly lower memory usage.
Allows retrieving the filename and line number easily.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 22 Feb 2025 00:04:51 +0100 |
| parents | 34ac05f6bd10 |
| children | 1b4f2d010141 |
comparison
equal
deleted
inserted
replaced
| 13744:34ac05f6bd10 | 13745:994ea8d54b72 |
|---|---|
| 46 end | 46 end |
| 47 | 47 |
| 48 function _M.get(host, key) | 48 function _M.get(host, key) |
| 49 local v = config[host][key]; | 49 local v = config[host][key]; |
| 50 if v and errors.is_error(v) then | 50 if v and errors.is_error(v) then |
| 51 log("warn", "%s", v.text); | 51 log("warn", "%s:%d: %s", v.context.filename, v.context.fileline, v.text); |
| 52 return nil; | 52 return nil; |
| 53 end | 53 end |
| 54 return v; | 54 return v; |
| 55 end | 55 end |
| 56 function _M.rawget(host, key) | 56 function _M.rawget(host, key) |
| 374 elseif credential_fallback_fatal then | 374 elseif credential_fallback_fatal then |
| 375 env.Credential = function() error("Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set", 2) end | 375 env.Credential = function() error("Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set", 2) end |
| 376 else | 376 else |
| 377 env.Credential = function() | 377 env.Credential = function() |
| 378 return errors.new({ | 378 return errors.new({ |
| 379 type = "continue", | 379 type = "continue"; |
| 380 text = ("%s:%d: Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set") | 380 text = "Credential() requires the $CREDENTIALS_DIRECTORY environment variable to be set"; |
| 381 :format(config_file, get_line_number(config_file)); | 381 }, { filename = config_file; fileline = get_line_number(config_file) }); |
| 382 }); | |
| 383 end | 382 end |
| 384 end | 383 end |
| 385 | 384 |
| 386 local chunk, err = envload(data, "@"..config_file, env); | 385 local chunk, err = envload(data, "@"..config_file, env); |
| 387 | 386 |
