Mishandling of multiline strings in user libraries

When user library is imported in user application Hubitat appends comment with library name and line number to each imported library line. Unfortunately this also applies to each line of multiline string, which results in modified multiline string.

Following example user library and app should demonstrate this problem.

library

library(
    author: 'bug reporter',
    category: 'hubitat bugs',
    description: 'demonstrates a bug',
    name: 'LibMultilineStringBug',
    namespace: 'hubitat.bugs.library.multilineString',
    documentationLink: ''
)

import groovy.transform.Field

@Field String problemString = '''first
one
two
three
last''';

app

definition(
    name: 'LibMultilineStringBug app',
    namespace: 'hubitat.bugs.library.multilineString',
    author: 'bug reporter',
    category: 'hubitat bugs',
    description: 'demonstrates a bug',
    iconUrl: '',
    iconX2Url: '',
)

preferences {
    page(name: 'mainPage', title: 'bug demo', install: true, uninstall: true) {
        section {
            paragraph(problemString);
        }
    }
}

void installed() {
}

void updated() {
}

void uninstalled() {
}

#include hubitat.bugs.library.multilineString.LibMultilineStringBug

Download of complete app code contains following part

String problemString = '''first // library marker hubitat.bugs.library.multilineString.LibMultilineStringBug, line 12
one // library marker hubitat.bugs.library.multilineString.LibMultilineStringBug, line 13
two // library marker hubitat.bugs.library.multilineString.LibMultilineStringBug, line 14
three // library marker hubitat.bugs.library.multilineString.LibMultilineStringBug, line 15
last'''; // library marker hubitat.bugs.library.multilineString.LibMultilineStringBug, line 16
1 Like

Known limitation of libraries, i.e. they don’t support multi line strings.

Such limitation should really be mentioned in library documentation.

I am not a huge fan of how it add a comment to every line. IMO wouldnt you get the same effect with a start and end comment? Can probably figure out the line numbers in another way.

// *** Libray Marker hubitat.bugs.library.multilineString.LibMultilineStringBug START ***
Library code.....
More Library code.....
// *** Libray Marker hubitat.bugs.library.multilineString.LibMultilineStringBug END ***
1 Like

The last time this was mentioned, this was the suggestion by @bravenel :

Have the same problem, therefore I asked:

Till now no answer... :sleepy:

Those comments are there to assist in creating meaningful error messages. They only appear in downloaded files. When you save a library to Libraries Code and it is compiled into the app or driver, there is no overhead from this.

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.