Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 65dec8f

Browse files
authored
Merge pull request #152 from codeoverflow-org/fix/disallow-empty-instance-names
Disallow empty instance names and show instance creation errors
2 parents 2cc3bb6 + 9e3c08c commit 65dec8f

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

nodecg-io-core/dashboard/authentication.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const spanPasswordNotice = document.getElementById("spanPasswordNotice") as HTML
1212

1313
// Add key listener to password input
1414
inputPassword?.addEventListener("keyup", function (event) {
15-
if (event.keyCode === 13) {
15+
if (event.keyCode === 13 || event.key === "Enter") {
1616
event.preventDefault();
1717
loadFramework();
1818
}

nodecg-io-core/dashboard/serviceInstance.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export async function deleteInstance(): Promise<void> {
146146

147147
// Create button
148148
export async function createInstance(): Promise<void> {
149+
showError(undefined);
149150
const service = selectService.options[selectService.options.selectedIndex].value;
150151
const name = inputInstanceName.value;
151152

@@ -154,7 +155,13 @@ export async function createInstance(): Promise<void> {
154155
instanceName: name,
155156
};
156157

157-
await sendAuthenticatedMessage("createServiceInstance", msg);
158+
try {
159+
await sendAuthenticatedMessage("createServiceInstance", msg);
160+
} catch (e) {
161+
showError(e);
162+
return;
163+
}
164+
158165
// Give the browser some time to create the new instance select option and to add them to the DOM
159166
setTimeout(() => {
160167
selectServiceInstance(name);

nodecg-io-core/extension/instanceManager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export class InstanceManager extends EventEmitter {
4545
* @return void if everything went fine and a string describing the issue if not
4646
*/
4747
createServiceInstance(serviceType: string, instanceName: string): Result<void> {
48+
if (!instanceName) {
49+
return error("Instance name must not be empty.");
50+
}
51+
4852
// Check if a instance with the same name already exists.
4953
if (this.serviceInstances[instanceName] !== undefined) {
5054
return error("A service instance with the same name already exists.");

0 commit comments

Comments
 (0)