• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RobotWebTools / rclnodejs / 19071410104

04 Nov 2025 02:08PM UTC coverage: 83.072% (+0.4%) from 82.711%
19071410104

Pull #1320

github

web-flow
Merge 9cad4567e into 3ad842cc4
Pull Request #1320: feat: add structured error handling with class error hierarchy

1032 of 1365 branches covered (75.6%)

Branch coverage included in aggregate %.

161 of 239 new or added lines in 25 files covered. (67.36%)

29 existing lines in 1 file now uncovered.

2354 of 2711 relevant lines covered (86.83%)

459.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.22
/lib/validator.js
1
// Copyright (c) 2017 Intel Corporation. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
'use strict';
16

17
const rclnodejs = require('./native_loader.js');
26✔
18
const { TypeValidationError, NameValidationError } = require('./errors.js');
26✔
19

20
/**
21
 * An object - Representing a validator in ROS.
22
 * @exports validator
23
 */
24
let validator = {
26✔
25
  _createErrorFromValidation: function (result, argumentName) {
26
    return new NameValidationError(argumentName, result[0], result[1]);
10✔
27
  },
28

29
  /**
30
   * Validate a given topic or service name, and throw an error if invalid.
31
   * @param {string} topic - The name of topic/service. and it must be fully-qualified and already expanded.
32
   * @return {boolean} - True if it is valid.
33
   */
34
  validateFullTopicName(topic) {
35
    if (typeof topic !== 'string') {
10!
NEW
36
      throw new TypeValidationError('topic', topic, 'string');
×
37
    }
38

39
    let result = rclnodejs.validateFullTopicName(topic);
10✔
40
    if (result === null) {
10✔
41
      return true;
8✔
42
    }
43
    throw this._createErrorFromValidation(result, 'topic');
2✔
44
  },
45

46
  /**
47
   * Validate a given node name, and throw an error if invalid.
48
   * @param {string} name - The name of node.
49
   * @return {boolean} - True if it is valid.
50
   */
51
  validateNodeName(name) {
52
    if (typeof name !== 'string') {
56!
NEW
53
      throw new TypeValidationError('name', name, 'string');
×
54
    }
55

56
    let result = rclnodejs.validateNodeName(name);
56✔
57
    if (result === null) {
56✔
58
      return true;
52✔
59
    }
60
    throw this._createErrorFromValidation(result, 'name');
4✔
61
  },
62

63
  /**
64
   * Validate a given topic or service name, and throw an error if invalid.
65
   * @param {string} topic - The name of topic/service and does not have to be fully-qualified and is not expanded.
66
   * @return {boolean} - True if it is valid.
67
   */
68
  validateTopicName(topic) {
69
    if (typeof topic !== 'string') {
5!
NEW
70
      throw new TypeValidationError('topic', topic, 'string');
×
71
    }
72

73
    let result = rclnodejs.validateTopicName(topic);
5✔
74
    if (result === null) {
5✔
75
      return true;
3✔
76
    }
77
    throw this._createErrorFromValidation(result, 'topic');
2✔
78
  },
79

80
  /**
81
   * Validate a given namespace, and throw an error if invalid.
82
   * @param {string} namespace - The namespace to be validated
83
   * @return {boolean} - True if it is valid.
84
   */
85
  validateNamespace(namespace) {
86
    if (typeof namespace !== 'string') {
4!
NEW
87
      throw new TypeValidationError('namespace', namespace, 'string');
×
88
    }
89

90
    let result = rclnodejs.validateNamespace(namespace);
4✔
91
    if (result === null) {
4✔
92
      return true;
2✔
93
    }
94
    throw this._createErrorFromValidation(result, 'namespace');
2✔
95
  },
96
};
97

98
module.exports = validator;
26✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc