---
title: "17.8 Common mistakes"
url: https://una-lang.org/en/learn/information-flow/common-mistakes/
release: v0.4.0
edition: "0.2"
---

# 17.8 Common mistakes

Each mistake below is a small change to the day-to-day program or to a step of this chapter, as it says. Each diagnostic names the place a value would flow into, the label it has, and the label that place allows; read those three, and the repair follows.

## 17.8.1 Dropping a label in a return type (U4001)

:::mistake
In [step 03](https://una-lang.org/en/learn/information-flow/labels-and-how-they-follow-data/#a-catalog-with-a-confidential-cost), declare the margin as a plain `Int`:

```diff include="steps/03-labels..mistakes/1:src/pricing.una" context="1" title="src/pricing.una"
--- a/src/pricing.una
+++ b/src/pricing.una
@@ -9,3 +9,3 @@
 --- The margin of a product, in cents. It is computed from the cost, so it is confidential too.
-margin(product: Product) -> confidential Int = product.price - product.cost
+margin(product: Product) -> Int = product.price - product.cost
 
```

```text include="mistakes/1/expected/rendered.txt#L1"
[U4001] Error: the result of `margin` is `Int`, and this value is `confidential Int`: a flow from `confidential` to `public`
```

*Why:* `product.cost` is `confidential`, so the difference is too, and a result is checked against the declared label. It happens when a function is first written with plain types, and a field it reads gains a label later. The message gives the declared type, `Int`, then the value's, `confidential Int`, then the direction of the flow.

*Fix:* declare `confidential Int`. A header is where callers learn what they receive.
:::

## 17.8.2 A sink without `accepts` (U4003)

:::mistake
Remove `accepts secret[PII]` from `Mailer`:

```diff include="day-to-day..mistakes/2:src/notices.una" context="1" title="src/notices.una"
--- a/src/notices.una
+++ b/src/notices.una
@@ -32,3 +32,2 @@
     fails ServiceError
-    accepts secret[PII]
 
```

```text include="mistakes/2/expected/rendered.txt#L1"
[U4003] Error: `@mailer.send` accepts `public` data, and this argument is `secret[PII]`
```

*Why:* an operation accepts `public` data unless it says more. It happens when a capability is declared before its data is labeled, as in chapter 12. una reports the address and the body, one diagnostic each, since each argument is its own sink; the mark points at the argument.

*Fix:* give the operation the ceiling of the service it stands for. Do not lower the data to fit: the mail service needs the real address.
:::

## 17.8.3 A branch that decides a public result (U4001)

:::mistake
In [step 19](https://una-lang.org/en/learn/information-flow/branches-and-failures-implicit-flows/#a-fee-decided-by-a-branch), declare the fee as a plain `Int`:

```diff include="steps/19-branches..mistakes/3:src/shipping.una" context="1" title="src/shipping.una"
--- a/src/shipping.una
+++ b/src/shipping.una
@@ -9,3 +9,3 @@
 --- what the customer spent, so the fee is confidential, even though 0 and 790 are not.
-shipping_fee(spent: confidential Int) -> confidential Int = if spent >= 50000 then 0 else 790
+shipping_fee(spent: confidential Int) -> Int = if spent >= 50000 then 0 else 790
 
```

```text include="mistakes/3/expected/rendered.txt#L1"
[U4001] Error: the result of `shipping_fee` is `public`, and which value it returns depends on this `confidential` condition: a flow from `confidential` to `public`
```

*Why:* the fee is a constant in each branch, but which branch runs depends on `spent`. It is easy to miss, since no labeled value appears in the result. The message says *which value it returns depends on this `confidential` condition*, and the mark points at the condition, since that is where the information enters.

*Fix:* declare `confidential Int`.
:::

## 17.8.4 A category that is not declared (U4007)

:::mistake
In [step 26](https://una-lang.org/en/learn/information-flow/categories/#a-courier-that-may-receive-a-phone-number), remove the `[labels]` table from `una.toml`:

```diff include="steps/26-categories..mistakes/4:una.toml" context="1" title="una.toml"
--- a/una.toml
+++ b/una.toml
@@ -5,5 +5,2 @@
 
-[labels]
-categories = ["PII"]
-
 [run]
```

```text include="mistakes/4/expected/rendered.txt#L1-L2,L10-L11"
[U4007] Error: label category `PII` is not declared in `[labels] categories` of `una.toml`
   ╭─[ src/courier.una:7:17 ]
[U4007] Error: label category `PII` is not declared in `[labels] categories` of `una.toml`
    ╭─[ src/courier.una:13:20 ]
```

*Why:* each package declares its categories, so a typo cannot create one. It happens when code is copied from another package, whose manifest declared the category. una reports each use of the category, one diagnostic each: in the field `phone`, and in the `accepts` clause of `book`. The marks point at the uses, not at the manifest, since that is where the unknown name is used.

*Fix:* declare `categories = ["PII"]` under `[labels]`.
:::

## 17.8.5 A trusted module that `una.toml` does not list (U7005)

:::mistake
Remove the `[trusted]` table of the day-to-day program:

```diff include="day-to-day..mistakes/5:una.toml" context="1" title="una.toml"
--- a/una.toml
+++ b/una.toml
@@ -8,5 +8,2 @@
 
-[trusted]
-modules = ["privacy"]
-
 [run]
```

```text include="mistakes/5/expected/rendered.txt#L1"
[U7005] Error: module `privacy` is `trusted` in its header but not listed in una.toml [trusted] modules
```

*Why:* trust is declared twice, in the module and in the manifest, so that adding it shows in review. It happens when a trusted module is copied into a package without its manifest line. The message names the module and the half of the declaration that is missing.

*Fix:* list the module under `[trusted] modules`, after a review of what it releases.
:::

## 17.8.6 A public `via` function (U4005)

:::mistake
Make `mask_email` public:

```diff include="day-to-day..mistakes/6:src/privacy.una" context="1" title="src/privacy.una"
--- a/src/privacy.una
+++ b/src/privacy.una
@@ -10,3 +10,3 @@
 
-mask_email(address: secret[PII] Text) -> public Text
+pub mask_email(address: secret[PII] Text) -> public Text
 =
```

```text include="mistakes/6/expected/rendered.txt#L1"
[U4005] Error: the `via` function of a policy is private to its trusted module, and `mask_email` is not; remove its `pub`, or declare it in this module
```

*Why:* a public `via` function would release data without the policy, so its calls would be missing from the report. It happens when a helper is made public to reuse it elsewhere, or to test it. The message names the function and gives both repairs.

*Fix:* keep `via` private, and call the policy, `masked_email`. An example can call the policy directly, as [section 17.7](https://una-lang.org/en/learn/information-flow/testing-it/#s17-7) does.
:::
