Skip to content

Commit 3396bc0

Browse files
committed
api: return reasonable error
There was "attempt to index local 'httpd' (a nil value)" error that doesn't get any useful information. This patch adds readable error message that tells you to check if the roles are properly included in the sequence. Closes #33
1 parent 9e8c17c commit 3396bc0

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Changed
1515

16+
- Unclear error message when `roles.httpd` config is not applied yet (#33).
17+
1618
## 0.3.0 - 2024-12-27
1719

1820
This release adds TLS support with `listen` configuration parameter.

roles/metrics-export.lua

+4
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ local function apply_http(conf)
369369
httpd:start()
370370
else
371371
httpd = httpd_role.get_server(target.value)
372+
if httpd == nil then
373+
error(('failed to get server by name %q, check that roles.httpd was' ..
374+
' already applied'):format(target.value))
375+
end
372376
end
373377

374378
http_servers[tostring(target.value) .. tostring(target.is_httpd_role)] = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
credentials:
2+
users:
3+
guest:
4+
roles: [super]
5+
6+
groups:
7+
group-001:
8+
replicasets:
9+
replicaset-001:
10+
instances:
11+
master:
12+
roles: [roles.metrics-export, roles.httpd]
13+
roles_cfg:
14+
roles.httpd:
15+
default:
16+
listen: 8085
17+
roles.metrics-export:
18+
http:
19+
- server: 'default'
20+
endpoints:
21+
- path: /metrics/prometheus
22+
format: prometheus
23+
metrics:
24+
enabled: true
25+
iproto:
26+
listen:
27+
- uri: '127.0.0.1:3313'

test/integration/error_test.lua

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
local fio = require('fio')
2+
local helpers = require('test.helpers')
3+
local server = require('test.helpers.server')
4+
5+
local t = require('luatest')
6+
local g = t.group()
7+
8+
g.before_all(function()
9+
helpers.skip_if_unsupported()
10+
end)
11+
12+
g.before_each(function(cg)
13+
cg.workdir = fio.tempdir()
14+
fio.mktree(cg.workdir)
15+
16+
fio.copytree(".rocks", fio.pathjoin(cg.workdir, ".rocks"))
17+
fio.copytree("roles", fio.pathjoin(cg.workdir, "roles"))
18+
end)
19+
20+
g.after_each(function(cg)
21+
fio.rmtree(cg.workdir)
22+
end)
23+
24+
g.test_incorrect_httpd_sequense = function(cg)
25+
cg.server = server:new({
26+
config_file = fio.abspath(fio.pathjoin('test', 'entrypoint', 'incorrect_roles_sequence.yaml')),
27+
chdir = cg.workdir,
28+
alias = 'master',
29+
workdir = cg.workdir,
30+
})
31+
32+
t.assert_error(function()
33+
cg.server:start({wait_until_ready = true})
34+
end)
35+
36+
t.assert_str_contains(
37+
cg.server.process.output_beautifier.stderr,
38+
'failed to get server by name "default", check that roles.httpd was already applied'
39+
)
40+
end

0 commit comments

Comments
 (0)