Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25189] Windows: Throw better error when calling style.apply with an incorrect TargetType

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionWon't Do
Resolution Date2021-02-11T12:14:57.000+0000
Affected Version/sRelease 6.2.0
Fix Version/sn/a
ComponentsWindows
Labelsn/a
ReporterEwan Harris
AssigneeUnknown
Created2017-08-23T09:40:55.000+0000
Updated2021-02-11T12:14:57.000+0000

Description

Description

When calling apply with a style, where the TargetType in the XAML style doesn't match the correct underlying control used by Titanium the error message is currently the below, it would be nice if we could catch the error correctly and then report this back to the user
[ERROR] ----- Titanium Javascript Runtime Error -----
[ERROR] In app.js: 6,12
[ERROR] Message: Uncaught Error: apply: unknown exception
var win = Ti.UI.createWindow({ backgroundColor: 'white' });
var lbl = Ti.UI.createLabel({
    text: 'label'
})
var style = Ti.UI.Windows.createStyle({ source: 'ms-appx:///Styles.xaml' });
style.apply(lbl, 'LabelStyle');
win.open();
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="LabelStyle" TargetType="TextBox">
        <Setter Property="Foreground" Value="Plum"></Setter>
    </Style>
</ResourceDictionary>

Steps to reproduce

Copy the above app.js and styles.xaml into your project

Build for a Windows target

Actual

Unknown exception error is thrown

Expected

A nicer error that maybe just spits back the error returned from nativeland? WinRT information: Cannot apply a Style with TargetType 'Windows.UI.Xaml.Controls.TextBox' to an object of type 'Windows.UI.Xaml.Controls.TextBlock'.

Comments

No comments

JSON Source