Skip to content

Commit

Permalink
Added showErrorMessage() to output TDML editor error messages to the …
Browse files Browse the repository at this point in the history
…user.
  • Loading branch information
lrbarber authored Oct 16, 2024
1 parent 817221d commit b8452a5
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/tdmlEditor/utilities/tdmlXmlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { readFileSync, writeFileSync } from 'fs'
import os from 'os'
import { join, resolve, sep, relative, dirname } from 'path'
import { Element, ElementCompact, js2xml, xml2js } from 'xml-js'
import * as vscode from 'vscode'

/*
* Note that the functions in this file assumes the structure of a TDML file
Expand Down Expand Up @@ -290,23 +291,27 @@ export async function copyTestCase(
)

if (sourceTestSuite === undefined) {
throw `No test suite found in source XML buffer`
vscode.window.showErrorMessage('TDML ERROR: No test suite found in source XML buffer')
throw `No test suite found in source XML buffer`
}

if (sourceTestSuite.length !== 1) {
throw `More than one test suite found in source XML buffer`
vscode.window.showErrorMessage('TDML ERROR: More than one test suite found in source XML buffer')
throw `More than one test suite found in source XML buffer`
}

const sourceTestCase = sourceTestSuite[0].elements?.filter((childNode) =>
childNode.name?.endsWith(testCaseElement)
)

if (sourceTestCase === undefined) {
throw `No test case found in source XML buffer`
vscode.window.showErrorMessage('TDML ERROR: No test case found in source XML buffer')
throw `No test case found in source XML buffer`
}

if (sourceTestCase.length !== 1) {
throw `More than one test case found in source XML buffer`
vscode.window.showErrorMessage('TDML ERROR: More than one test case found in source XML buffer')
throw `More than one test case found in source XML buffer`
}

const rootNode = (xmlObj as Element).elements?.filter((node) =>
Expand Down Expand Up @@ -379,11 +384,13 @@ export async function copyTestCase(
)

if (destinationTestSuite === undefined) {
throw `No test suites found in destination XML buffer`
vscode.window.showErrorMessage('TDML ERROR: No test suites found in destination XML buffer')
throw `No test suites found in destination XML buffer`
}

if (destinationTestSuite.length !== 1) {
throw `More than one test suite found in destination XML buffer`
vscode.window.showErrorMessage('TDML ERROR: More than one test suite found in destination XML buffer')
throw `More than one test suite found in destination XML buffer`
}

const destinationTestCases = destinationTestSuite[0].elements?.filter(
Expand All @@ -398,6 +405,7 @@ export async function copyTestCase(
testCase.attributes[testCaseNameAttribute] ===
sourceTestCase[0].attributes[testCaseNameAttribute]
) {
vscode.window.showErrorMessage('TDML ERROR: Duplicate Test Case Name')
throw `Duplicate Test Case Name Found`
}
})
Expand Down

0 comments on commit b8452a5

Please sign in to comment.