-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors-ux.qmd
More file actions
139 lines (94 loc) · 4.69 KB
/
Copy patherrors-ux.qmd
File metadata and controls
139 lines (94 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
title: "Error Messages & User Experience"
---
JASP targets researchers and students who may have limited statistical or programming experience. Every analysis should guide users towards correct interpretation and fail gracefully when something goes wrong.
## Design Philosophy
Three principles from the JASP Human Guide:
1. **Be proactive, not reactive** — check assumptions and warn before producing misleading results.
2. **Write for humans** — error messages should explain what went wrong and suggest a fix, not dump a stack trace.
3. **Be consistent** — use the standardised error messages below so users learn to recognise common patterns.
## Types of Messages
| Type | Where it appears | Purpose |
|------|-----------------|---------|
| **Analysis error** | Red banner above results | Unrecoverable problem — analysis cannot produce output |
| **Footnote** | Below a table | Warning or caveat about specific results |
| **Value error** | Inline in a table cell | A specific cell could not be computed |
### Setting an Analysis Error
```r
table <- createJaspTable(title = "Results")
table$setError("The dependent variable contains only missing values.")
```
The error is attached to a specific output element (table, plot, or container). If attached to a container, all child elements inherit the error state.
### Adding Footnotes
```r
table$addFootnote(
message = gettext("Levene's test is significant (p < .05), suggesting a violation of the equal variances assumption."),
colNames = "p",
rowNames = "levene"
)
```
### .hasErrors() — Validate Before Computing
Call `.hasErrors()` on your dataset to check common problems **before** attempting computation:
```r
.hasErrors(dataset,
type = c("infinity", "observations", "variance"),
observations.amount = "< 2",
exitAnalysisIfErrors = TRUE
)
```
Available check types:
| Type | What it checks |
|------|---------------|
| `infinity` | Infinite values in the data |
| `observations` | Too few observations (specify `observations.amount`) |
| `variance` | Zero variance in a variable |
| `factorLevels` | Too few factor levels (specify `factorLevels.amount`) |
| `negativeValues` | Negative values where not expected |
| `integerValues` | Non-integer values where integers are required |
| `duplicateValues` | Duplicate values in a variable |
When `exitAnalysisIfErrors = TRUE`, the error is set automatically and the analysis stops cleanly.
## Standardised Error Messages
Use these exact phrasings when the situation matches. This ensures consistency across all JASP modules and simplifies translation.
### Not Enough Observations
> "Not enough observations. The analysis requires at least *N* observations."
### Not Enough Factor Levels
> "The factor '*variable*' has fewer than 2 levels after removing empty levels."
### Zero Variance
> "The variable '*variable*' has zero variance. The analysis cannot proceed."
### Infinite Values
> "The variable '*variable*' contains infinite values."
### Singular Matrix / Convergence Failures
> "The model could not be estimated. The design matrix is (near-)singular."
> "The model did not converge within *N* iterations."
### Bayesian-Specific
> "The Bayes factor could not be computed. This may be due to a singular design matrix."
> "The posterior samples could not be obtained. Consider increasing the number of MCMC samples."
## Assumption Checking
JASP analyses should check assumptions and report violations as footnotes:
```r
if (leveneResult$p < 0.05) {
table$addFootnote(
message = gettext("Levene's test is significant (p < .05), suggesting a violation of the equal variances assumption.")
)
}
```
### Where to Validate
Validate at system boundaries only:
| Boundary | Action |
|----------|--------|
| Dataset columns | Use `.hasErrors()` checks |
| User text input (TextField, FormulaField) | Validate in QML via `inputType` or in R |
| Numeric input (IntegerField, DoubleField) | Use QML `min`/`max` properties |
| QML dropdowns / checkboxes | No validation needed — values are constrained by the UI |
Do **not** add defensive checks for values that cannot occur because the UI prevents them. Trust [QML input constraints](qml-interface.qmd#sec-qml-input-components).
## Writing Good Error Messages
::: {.callout-tip}
### Checklist
- [ ] Is the message a complete sentence?
- [ ] Does it say **what** went wrong?
- [ ] Does it suggest **what the user can do**?
- [ ] Is it wrapped in `gettext()` or `gettextf()` for translation?
- [ ] Does it avoid R jargon (e.g., "NULL", "NA", "vector")?
:::
**Good**: `gettextf("The grouping variable '%s' has fewer than 2 levels. Ensure both groups are present in the data.", groupVar)`
**Bad**: `"Error in grouping variable"` — says nothing about the cause or remedy.